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
24 // File : SMESHGUI_TranslationDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_TranslationDlg.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
43 #include "SUIT_Desktop.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Session.h"
46 #include "SUIT_MessageBox.h"
48 #include "LightApp_Application.h"
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_Selection.h"
52 #include "SVTK_ViewWindow.h"
53 #include "SVTK_Selector.h"
54 #include "SALOME_ListIO.hxx"
55 #include "SALOMEDSClient_SObject.hxx"
57 #include "utilities.h"
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <qapplication.h>
65 #include <qbuttongroup.h>
66 #include <qgroupbox.h>
68 #include <qlineedit.h>
69 #include <qpushbutton.h>
70 #include <qradiobutton.h>
71 #include <qcheckbox.h>
77 #include "SALOMEconfig.h"
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 \brief Simple 'busy state' flag locker.
94 //! Constructor. Sets passed boolean flag to \c true.
95 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
96 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
97 ~BusyLocker() { myBusy = false; }
99 bool& myBusy; //! External 'busy state' boolean flag
102 //=================================================================================
103 // class : SMESHGUI_TranslationDlg()
105 //=================================================================================
106 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const char* name,
107 bool modal, WFlags fl)
108 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
109 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
110 mySMESHGUI( theModule ),
111 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
113 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
114 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
115 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
118 setName("SMESHGUI_TranslationDlg");
120 setCaption(tr("SMESH_TRANSLATION"));
121 setSizeGripEnabled(TRUE);
122 SMESHGUI_TranslationDlgLayout = new QGridLayout(this);
123 SMESHGUI_TranslationDlgLayout->setSpacing(6);
124 SMESHGUI_TranslationDlgLayout->setMargin(11);
126 /***************************************************************/
127 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
128 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth()));
129 GroupConstructors->setTitle(tr("SMESH_TRANSLATION" ));
130 GroupConstructors->setExclusive(TRUE);
131 GroupConstructors->setColumnLayout(0, Qt::Vertical);
132 GroupConstructors->layout()->setSpacing(0);
133 GroupConstructors->layout()->setMargin(0);
134 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
135 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
136 GroupConstructorsLayout->setSpacing(6);
137 GroupConstructorsLayout->setMargin(11);
138 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
139 RadioButton1->setText(tr("" ));
140 RadioButton1->setPixmap(image0);
141 GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
142 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
143 RadioButton2->setText(tr("" ));
144 RadioButton2->setPixmap(image1);
145 GroupConstructorsLayout->addWidget(RadioButton2, 0, 2 );
146 SMESHGUI_TranslationDlgLayout->addWidget(GroupConstructors, 0, 0);
148 /***************************************************************/
149 GroupButtons = new QGroupBox(this, "GroupButtons");
150 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
151 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
152 GroupButtons->setTitle(tr("" ));
153 GroupButtons->setColumnLayout(0, Qt::Vertical);
154 GroupButtons->layout()->setSpacing(0);
155 GroupButtons->layout()->setMargin(0);
156 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
157 GroupButtonsLayout->setAlignment(Qt::AlignTop);
158 GroupButtonsLayout->setSpacing(6);
159 GroupButtonsLayout->setMargin(11);
160 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
161 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
162 buttonHelp->setAutoDefault(TRUE);
163 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
164 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
165 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
166 buttonCancel->setAutoDefault(TRUE);
167 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
168 buttonApply = new QPushButton(GroupButtons, "buttonApply");
169 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
170 buttonApply->setAutoDefault(TRUE);
171 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
172 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
173 GroupButtonsLayout->addItem(spacer_9, 0, 2);
174 buttonOk = new QPushButton(GroupButtons, "buttonOk");
175 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
176 buttonOk->setAutoDefault(TRUE);
177 buttonOk->setDefault(TRUE);
178 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
179 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons, 2, 0);
181 /***************************************************************/
182 GroupArguments = new QGroupBox(this, "GroupArguments");
183 GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
184 GroupArguments->setColumnLayout(0, Qt::Vertical);
185 GroupArguments->layout()->setSpacing(0);
186 GroupArguments->layout()->setMargin(0);
187 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
188 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
189 GroupArgumentsLayout->setSpacing(6);
190 GroupArgumentsLayout->setMargin(11);
192 // Controls for elements selection
193 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
194 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
195 TextLabelElements->setFixedWidth(74);
196 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
198 SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton");
199 SelectElementsButton->setText(tr("" ));
200 SelectElementsButton->setPixmap(image2);
201 SelectElementsButton->setToggleButton(FALSE);
202 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
204 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
205 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
206 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
208 // Control for the whole mesh selection
209 CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
210 CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
211 GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
213 // Controls for vector and points selection
214 TextLabel1 = new QLabel(GroupArguments, "TextLabel1");
215 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
217 SelectButton1 = new QPushButton(GroupArguments, "SelectButton1");
218 SelectButton1->setText(tr("" ));
219 SelectButton1->setPixmap(image2);
220 SelectButton1->setToggleButton(FALSE);
221 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
223 TextLabel1_1 = new QLabel(GroupArguments, "TextLabel1_1");
224 TextLabel1_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
225 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
227 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
228 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
230 TextLabel1_2 = new QLabel(GroupArguments, "TextLabel1_2");
231 TextLabel1_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
232 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
234 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
235 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
237 TextLabel1_3 = new QLabel(GroupArguments, "TextLabel1_3");
238 TextLabel1_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
239 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
241 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
242 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
244 TextLabel2 = new QLabel(GroupArguments, "TextLabel2");
245 TextLabel2->setText(tr("SMESH_POINT_2" ));
246 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
248 SelectButton2 = new QPushButton(GroupArguments, "SelectButton2");
249 SelectButton2->setText(tr("" ));
250 SelectButton2->setPixmap(image2);
251 SelectButton2->setToggleButton(FALSE);
252 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
254 TextLabel2_1 = new QLabel(GroupArguments, "TextLabel2_1");
255 TextLabel2_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
256 TextLabel2_1->setText(tr("SMESH_X" ));
257 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
259 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
260 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
262 TextLabel2_2 = new QLabel(GroupArguments, "TextLabel2_2");
263 TextLabel2_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
264 TextLabel2_2->setText(tr("SMESH_Y" ));
265 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
267 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
268 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
270 TextLabel2_3 = new QLabel(GroupArguments, "TextLabel2_3");
271 TextLabel2_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
272 TextLabel2_3->setText(tr("SMESH_Z"));
273 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
275 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
276 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
278 // Controls for "Create a copy" option
279 // CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
280 // CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
281 // GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
283 // switch of action type
284 ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup");
285 ActionGroup->setExclusive(true);
286 ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON);
287 ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON);
288 ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON);
289 GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 4, 6, 0, 3);
291 // CheckBox for groups generation
292 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
293 MakeGroupsCheck->setChecked(false);
294 GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 4, 7);
296 // Name of a mesh to create
297 LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh");
298 GroupArgumentsLayout->addMultiCellWidget(LineEditNewMesh, 6, 6, 4, 7);
300 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0);
302 /* Initialisations */
303 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
304 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
305 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
306 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
307 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
308 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
310 GroupArguments->show();
311 RadioButton1->setChecked(TRUE);
313 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
315 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
317 // Costruction of the logical filter
318 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
319 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
321 QPtrList<SUIT_SelectionFilter> aListOfFilters;
322 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
323 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
325 myMeshOrSubMeshOrGroupFilter =
326 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
328 myHelpFileName = "translation_page.html";
332 /* signals and slots connections */
333 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
334 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
335 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
336 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
337 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
339 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
340 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
341 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
343 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
344 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
345 /* to close dialog if study change */
346 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
347 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
348 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
349 connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int)));
351 this->show(); /* displays Dialog */
353 ConstructorsClicked(0);
354 SelectionIntoArgument();
355 onActionClicked(MOVE_ELEMS_BUTTON);
359 //=================================================================================
360 // function : ~SMESHGUI_TranslationDlg()
361 // purpose : Destroys the object and frees any allocated resources
362 //=================================================================================
363 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
365 // no need to delete child widgets, Qt does it all for us
368 //=================================================================================
371 //=================================================================================
372 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
376 myEditCurrentArgument = 0;
377 LineEditElements->clear();
381 buttonOk->setEnabled(false);
382 buttonApply->setEnabled(false);
385 myMesh = SMESH::SMESH_Mesh::_nil();
388 SpinBox1_1->SetValue(0.0);
389 SpinBox1_2->SetValue(0.0);
390 SpinBox1_3->SetValue(0.0);
391 SpinBox2_1->SetValue(0.0);
392 SpinBox2_2->SetValue(0.0);
393 SpinBox2_3->SetValue(0.0);
395 ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE);
396 CheckBoxMesh->setChecked(false);
397 // MakeGroupsCheck->setChecked(false);
398 // MakeGroupsCheck->setEnabled(false);
403 //=================================================================================
404 // function : ConstructorsClicked()
405 // purpose : Radio button management
406 //=================================================================================
407 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
409 disconnect(mySelectionMgr, 0, this, 0);
411 switch (constructorId) {
414 TextLabel1->setText(tr("SMESH_POINT_1"));
415 TextLabel1_1->setText(tr("SMESH_X"));
416 TextLabel1_2->setText(tr("SMESH_Y"));
417 TextLabel1_3->setText(tr("SMESH_Z"));
419 SelectButton1->show();
421 SelectButton2->show();
422 TextLabel2_1->show();
424 TextLabel2_2->show();
426 TextLabel2_3->show();
432 TextLabel1->setText(tr("SMESH_VECTOR"));
433 TextLabel1_1->setText(tr("SMESH_DX"));
434 TextLabel1_2->setText(tr("SMESH_DY"));
435 TextLabel1_3->setText(tr("SMESH_DZ"));
437 SelectButton1->hide();
439 SelectButton2->hide();
440 TextLabel2_1->hide();
442 TextLabel2_2->hide();
444 TextLabel2_3->hide();
450 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
451 SMESH::SetPointRepresentation(false);
452 if (!CheckBoxMesh->isChecked())
453 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454 aViewWindow->SetSelectionMode( CellSelection );
457 myEditCurrentArgument = (QWidget*)LineEditElements;
458 LineEditElements->setFocus();
460 if (CheckBoxMesh->isChecked())
463 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
466 //=================================================================================
467 // function : ClickOnApply()
469 //=================================================================================
470 void SMESHGUI_TranslationDlg::ClickOnApply()
472 if (mySMESHGUI->isActiveStudyLocked() || myBusy )
474 BusyLocker lock( myBusy );
476 if (myNbOkElements) {
477 QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
479 SMESH::long_array_var anElementsId = new SMESH::long_array;
481 anElementsId->length(aListElementsId.count());
482 for (int i = 0; i < aListElementsId.count(); i++)
483 anElementsId[i] = aListElementsId[i].toInt();
485 SMESH::DirStruct aVector;
486 if (GetConstructorId() == 0) {
487 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
488 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
489 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
490 } else if (GetConstructorId() == 1) {
491 aVector.PS.x = SpinBox1_1->GetValue();
492 aVector.PS.y = SpinBox1_2->GetValue();
493 aVector.PS.z = SpinBox1_3->GetValue();
496 int actionButton = ActionGroup->id( ActionGroup->selected() );
497 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
499 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
500 QApplication::setOverrideCursor(Qt::waitCursor);
501 switch ( actionButton ) {
502 case MOVE_ELEMS_BUTTON:
503 aMeshEditor->Translate(anElementsId, aVector, false);
505 case COPY_ELEMS_BUTTON:
507 SMESH::ListOfGroups_var groups =
508 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
510 aMeshEditor->Translate(anElementsId, aVector, true);
512 case MAKE_MESH_BUTTON:
513 SMESH::SMESH_Mesh_var mesh =
514 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
515 LineEditNewMesh->text().latin1());
517 QApplication::restoreOverrideCursor();
522 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
523 actionButton == MAKE_MESH_BUTTON )
524 mySMESHGUI->updateObjBrowser(true); // new groups may appear
526 ConstructorsClicked(GetConstructorId());
527 SelectionIntoArgument();
531 //=================================================================================
532 // function : ClickOnOk()
534 //=================================================================================
535 void SMESHGUI_TranslationDlg::ClickOnOk()
541 //=================================================================================
542 // function : ClickOnCancel()
544 //=================================================================================
545 void SMESHGUI_TranslationDlg::ClickOnCancel()
547 disconnect(mySelectionMgr, 0, this, 0);
548 mySelectionMgr->clearFilters();
549 //mySelectionMgr->clearSelected();
550 SMESH::SetPointRepresentation(false);
551 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
552 aViewWindow->SetSelectionMode( ActorSelection );
553 mySMESHGUI->ResetState();
557 //=================================================================================
558 // function : ClickOnHelp()
560 //=================================================================================
561 void SMESHGUI_TranslationDlg::ClickOnHelp()
563 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
565 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
569 platform = "winapplication";
571 platform = "application";
573 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
574 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
575 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
576 QObject::tr("BUT_OK"));
580 //=======================================================================
581 // function : onTextChange()
583 //=======================================================================
584 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
586 QLineEdit* send = (QLineEdit*)sender();
589 BusyLocker lock( myBusy );
591 if (send == LineEditElements)
594 buttonOk->setEnabled(false);
595 buttonApply->setEnabled(false);
597 // hilight entered elements
598 SMDS_Mesh* aMesh = 0;
600 aMesh = myActor->GetObject()->GetMesh();
603 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
605 TColStd_MapOfInteger newIndices;
607 QStringList aListId = QStringList::split(" ", theNewText, false);
609 if (send == LineEditElements) {
610 for (int i = 0; i < aListId.count(); i++) {
611 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
613 newIndices.Add(e->GetID());
618 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
619 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
620 aViewWindow->highlight( anIO, true, true );
622 myElementsId = theNewText;
625 if (myNbOkElements) {
626 buttonOk->setEnabled(true);
627 buttonApply->setEnabled(true);
632 //=================================================================================
633 // function : SelectionIntoArgument()
634 // purpose : Called when selection as changed or other case
635 //=================================================================================
636 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
640 BusyLocker lock( myBusy );
644 QString aString = "";
646 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
647 LineEditElements->setText(aString);
649 buttonOk->setEnabled(false);
650 buttonApply->setEnabled(false);
653 if (!GroupButtons->isEnabled()) // inactive
658 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
660 int nbSel = aList.Extent();
664 Handle(SALOME_InteractiveObject) IO = aList.First();
665 myMesh = SMESH::GetMeshByIO(IO);
666 if (myMesh->_is_nil())
669 myActor = SMESH::FindActorByObject(myMesh);
671 myActor = SMESH::FindActorByEntry(IO->getEntry());
677 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
680 // MakeGroups is available if there are groups and "Copy"
681 if ( myMesh->NbGroups() == 0 ) {
682 MakeGroupsCheck->setChecked(false);
683 MakeGroupsCheck->setEnabled(false);
685 else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
686 MakeGroupsCheck->setEnabled(true);
689 if (CheckBoxMesh->isChecked()) {
690 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
692 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
694 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
698 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
699 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
701 myElementsId += QString(" %1").arg(i);
705 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
707 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
709 // get IDs from submesh
710 SMESH::long_array_var anElementsIds = new SMESH::long_array;
711 anElementsIds = aSubMesh->GetElementsId();
712 for (int i = 0; i < anElementsIds->length(); i++) {
713 myElementsId += QString(" %1").arg(anElementsIds[i]);
715 aNbUnits = anElementsIds->length();
718 SMESH::SMESH_GroupBase_var aGroup =
719 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
720 if (aGroup->_is_nil())
723 // get IDs from smesh group
724 SMESH::long_array_var anElementsIds = new SMESH::long_array;
725 anElementsIds = aGroup->GetListOfID();
726 for (int i = 0; i < anElementsIds->length(); i++) {
727 myElementsId += QString(" %1").arg(anElementsIds[i]);
729 aNbUnits = anElementsIds->length();
732 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
733 myElementsId = aString;
739 myNbOkElements = true;
741 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
745 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
749 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
757 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
758 SpinBox1_1->SetValue(x);
759 SpinBox1_2->SetValue(y);
760 SpinBox1_3->SetValue(z);
761 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
762 SpinBox2_1->SetValue(x);
763 SpinBox2_2->SetValue(y);
764 SpinBox2_3->SetValue(z);
768 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
769 LineEditElements->setText(aString);
770 LineEditElements->repaint();
775 if (myNbOkElements) {
776 buttonOk->setEnabled(true);
777 buttonApply->setEnabled(true);
781 //=================================================================================
782 // function : SetEditCurrentArgument()
784 //=================================================================================
785 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
788 BusyLocker lock( myBusy );
790 QPushButton* send = (QPushButton*)sender();
792 disconnect(mySelectionMgr, 0, this, 0);
793 mySelectionMgr->clearSelected();
794 mySelectionMgr->clearFilters();
796 if (send == SelectElementsButton) {
797 myEditCurrentArgument = (QWidget*)LineEditElements;
798 SMESH::SetPointRepresentation(false);
799 if (CheckBoxMesh->isChecked()) {
800 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
801 aViewWindow->SetSelectionMode( ActorSelection );
802 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
805 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
806 aViewWindow->SetSelectionMode( CellSelection );
808 } else if (send == SelectButton1) {
809 myEditCurrentArgument = (QWidget*)SpinBox1_1;
810 SMESH::SetPointRepresentation(true);
812 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813 aViewWindow->SetSelectionMode( NodeSelection );
814 } else if (send == SelectButton2) {
815 myEditCurrentArgument = (QWidget*)SpinBox2_1;
816 SMESH::SetPointRepresentation(true);
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode( NodeSelection );
822 myEditCurrentArgument->setFocus();
823 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
824 SelectionIntoArgument();
827 //=================================================================================
828 // function : DeactivateActiveDialog()
830 //=================================================================================
831 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
833 if (GroupConstructors->isEnabled()) {
834 GroupConstructors->setEnabled(false);
835 GroupArguments->setEnabled(false);
836 GroupButtons->setEnabled(false);
837 mySMESHGUI->ResetState();
838 mySMESHGUI->SetActiveDialogBox(0);
842 //=================================================================================
843 // function : ActivateThisDialog()
845 //=================================================================================
846 void SMESHGUI_TranslationDlg::ActivateThisDialog()
848 /* Emit a signal to deactivate the active dialog */
849 mySMESHGUI->EmitSignalDeactivateDialog();
850 GroupConstructors->setEnabled(true);
851 GroupArguments->setEnabled(true);
852 GroupButtons->setEnabled(true);
854 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode( CellSelection );
859 // SelectionIntoArgument();
862 //=================================================================================
863 // function : enterEvent()
865 //=================================================================================
866 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
868 if (!GroupConstructors->isEnabled())
869 ActivateThisDialog();
872 //=================================================================================
873 // function : closeEvent()
875 //=================================================================================
876 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
878 /* same than click on cancel button */
879 this->ClickOnCancel();
882 //=======================================================================
883 //function : hideEvent
884 //purpose : caused by ESC key
885 //=======================================================================
886 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
892 //=======================================================================
893 //function : onSelectMesh
895 //=======================================================================
896 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
899 TextLabelElements->setText(tr("SMESH_NAME"));
901 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
903 if (myEditCurrentArgument != LineEditElements) {
904 LineEditElements->clear();
908 mySelectionMgr->clearFilters();
909 SMESH::SetPointRepresentation(false);
912 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
913 aViewWindow->SetSelectionMode( ActorSelection );
914 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
915 LineEditElements->setReadOnly(true);
917 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
918 aViewWindow->SetSelectionMode( CellSelection );
919 LineEditElements->setReadOnly(false);
920 onTextChange(LineEditElements->text());
923 SelectionIntoArgument();
926 //=======================================================================
927 //function : onActionClicked
928 //purpose : slot called when an action type changed
929 //=======================================================================
931 void SMESHGUI_TranslationDlg::onActionClicked(int button)
934 case MOVE_ELEMS_BUTTON:
935 MakeGroupsCheck->setEnabled(false);
936 LineEditNewMesh->setEnabled(false);
938 case COPY_ELEMS_BUTTON:
939 LineEditNewMesh->setEnabled(false);
940 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
941 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
942 MakeGroupsCheck->setEnabled(true);
944 MakeGroupsCheck->setEnabled(false);
946 case MAKE_MESH_BUTTON:
947 LineEditNewMesh->setEnabled(true);
948 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
949 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
950 MakeGroupsCheck->setEnabled(true);
952 MakeGroupsCheck->setEnabled(false);
958 //=======================================================================
959 //function : setNewMeshName
960 //purpose : update contents of LineEditNewMesh
961 //=======================================================================
963 void SMESHGUI_TranslationDlg::setNewMeshName()
965 LineEditNewMesh->setText("");
966 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
968 if ( CheckBoxMesh->isChecked() ) {
969 name = LineEditElements->text();
972 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
973 name = meshSO->GetName();
975 if ( !name.isEmpty() )
976 LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "translated"));
980 //=================================================================================
981 // function : GetConstructorId()
983 //=================================================================================
984 int SMESHGUI_TranslationDlg::GetConstructorId()
986 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
987 return GroupConstructors->id(GroupConstructors->selected());
991 //=================================================================================
992 // function : keyPressEvent()
994 //=================================================================================
995 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
997 QDialog::keyPressEvent( e );
998 if ( e->isAccepted() )
1001 if ( e->key() == Key_F1 )