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
85 //=================================================================================
86 // class : SMESHGUI_TranslationDlg()
88 //=================================================================================
89 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const char* name,
90 bool modal, WFlags fl)
91 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
92 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
96 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
97 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
98 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setName("SMESHGUI_TranslationDlg");
103 setCaption(tr("SMESH_TRANSLATION"));
104 setSizeGripEnabled(TRUE);
105 SMESHGUI_TranslationDlgLayout = new QGridLayout(this);
106 SMESHGUI_TranslationDlgLayout->setSpacing(6);
107 SMESHGUI_TranslationDlgLayout->setMargin(11);
109 /***************************************************************/
110 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
111 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth()));
112 GroupConstructors->setTitle(tr("SMESH_TRANSLATION" ));
113 GroupConstructors->setExclusive(TRUE);
114 GroupConstructors->setColumnLayout(0, Qt::Vertical);
115 GroupConstructors->layout()->setSpacing(0);
116 GroupConstructors->layout()->setMargin(0);
117 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
118 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
119 GroupConstructorsLayout->setSpacing(6);
120 GroupConstructorsLayout->setMargin(11);
121 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
122 RadioButton1->setText(tr("" ));
123 RadioButton1->setPixmap(image0);
124 GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
125 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
126 RadioButton2->setText(tr("" ));
127 RadioButton2->setPixmap(image1);
128 GroupConstructorsLayout->addWidget(RadioButton2, 0, 2 );
129 SMESHGUI_TranslationDlgLayout->addWidget(GroupConstructors, 0, 0);
131 /***************************************************************/
132 GroupButtons = new QGroupBox(this, "GroupButtons");
133 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
134 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
135 GroupButtons->setTitle(tr("" ));
136 GroupButtons->setColumnLayout(0, Qt::Vertical);
137 GroupButtons->layout()->setSpacing(0);
138 GroupButtons->layout()->setMargin(0);
139 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
140 GroupButtonsLayout->setAlignment(Qt::AlignTop);
141 GroupButtonsLayout->setSpacing(6);
142 GroupButtonsLayout->setMargin(11);
143 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
144 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
145 buttonHelp->setAutoDefault(TRUE);
146 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
147 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
148 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
149 buttonCancel->setAutoDefault(TRUE);
150 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
151 buttonApply = new QPushButton(GroupButtons, "buttonApply");
152 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
153 buttonApply->setAutoDefault(TRUE);
154 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
155 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
156 GroupButtonsLayout->addItem(spacer_9, 0, 2);
157 buttonOk = new QPushButton(GroupButtons, "buttonOk");
158 buttonOk->setText(tr("SMESH_BUT_OK" ));
159 buttonOk->setAutoDefault(TRUE);
160 buttonOk->setDefault(TRUE);
161 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
162 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons, 2, 0);
164 /***************************************************************/
165 GroupArguments = new QGroupBox(this, "GroupArguments");
166 GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
167 GroupArguments->setColumnLayout(0, Qt::Vertical);
168 GroupArguments->layout()->setSpacing(0);
169 GroupArguments->layout()->setMargin(0);
170 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
171 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
172 GroupArgumentsLayout->setSpacing(6);
173 GroupArgumentsLayout->setMargin(11);
175 // Controls for elements selection
176 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
177 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
178 TextLabelElements->setFixedWidth(74);
179 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
181 SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton");
182 SelectElementsButton->setText(tr("" ));
183 SelectElementsButton->setPixmap(image2);
184 SelectElementsButton->setToggleButton(FALSE);
185 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
187 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
188 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
189 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
191 // Control for the whole mesh selection
192 CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
193 CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
194 GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
196 // Controls for vector and points selection
197 TextLabel1 = new QLabel(GroupArguments, "TextLabel1");
198 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
200 SelectButton1 = new QPushButton(GroupArguments, "SelectButton1");
201 SelectButton1->setText(tr("" ));
202 SelectButton1->setPixmap(image2);
203 SelectButton1->setToggleButton(FALSE);
204 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
206 TextLabel1_1 = new QLabel(GroupArguments, "TextLabel1_1");
207 TextLabel1_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
208 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
210 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
211 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
213 TextLabel1_2 = new QLabel(GroupArguments, "TextLabel1_2");
214 TextLabel1_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
215 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
217 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
218 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
220 TextLabel1_3 = new QLabel(GroupArguments, "TextLabel1_3");
221 TextLabel1_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
222 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
224 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
225 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
227 TextLabel2 = new QLabel(GroupArguments, "TextLabel2");
228 TextLabel2->setText(tr("SMESH_POINT_2" ));
229 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
231 SelectButton2 = new QPushButton(GroupArguments, "SelectButton2");
232 SelectButton2->setText(tr("" ));
233 SelectButton2->setPixmap(image2);
234 SelectButton2->setToggleButton(FALSE);
235 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
237 TextLabel2_1 = new QLabel(GroupArguments, "TextLabel2_1");
238 TextLabel2_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
239 TextLabel2_1->setText(tr("SMESH_X" ));
240 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
242 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
243 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
245 TextLabel2_2 = new QLabel(GroupArguments, "TextLabel2_2");
246 TextLabel2_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
247 TextLabel2_2->setText(tr("SMESH_Y" ));
248 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
250 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
251 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
253 TextLabel2_3 = new QLabel(GroupArguments, "TextLabel2_3");
254 TextLabel2_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
255 TextLabel2_3->setText(tr("SMESH_Z"));
256 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
258 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
259 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
261 // Controls for "Create a copy" option
262 // CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
263 // CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
264 // GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
266 // switch of action type
267 ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup");
268 ActionGroup->setExclusive(true);
269 ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON);
270 ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON);
271 ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON);
272 GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 4, 6, 0, 3);
274 // CheckBox for groups generation
275 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
276 MakeGroupsCheck->setChecked(false);
277 GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 4, 7);
279 // Name of a mesh to create
280 LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh");
281 GroupArgumentsLayout->addMultiCellWidget(LineEditNewMesh, 6, 6, 4, 7);
283 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0);
285 /* Initialisations */
286 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
287 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
288 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
289 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
290 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
291 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
293 GroupArguments->show();
294 RadioButton1->setChecked(TRUE);
296 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
298 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
300 // Costruction of the logical filter
301 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
302 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
304 QPtrList<SUIT_SelectionFilter> aListOfFilters;
305 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
306 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
308 myMeshOrSubMeshOrGroupFilter =
309 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
311 myHelpFileName = "translation_page.html";
315 /* signals and slots connections */
316 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
317 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
318 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
319 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
320 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
322 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
323 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
324 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
326 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
327 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
328 /* to close dialog if study change */
329 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
330 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
331 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
332 connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int)));
334 this->show(); /* displays Dialog */
336 ConstructorsClicked(0);
337 SelectionIntoArgument();
338 onActionClicked(MOVE_ELEMS_BUTTON);
342 //=================================================================================
343 // function : ~SMESHGUI_TranslationDlg()
344 // purpose : Destroys the object and frees any allocated resources
345 //=================================================================================
346 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
348 // no need to delete child widgets, Qt does it all for us
351 //=================================================================================
354 //=================================================================================
355 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
359 myEditCurrentArgument = 0;
360 LineEditElements->clear();
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
368 myMesh = SMESH::SMESH_Mesh::_nil();
371 SpinBox1_1->SetValue(0.0);
372 SpinBox1_2->SetValue(0.0);
373 SpinBox1_3->SetValue(0.0);
374 SpinBox2_1->SetValue(0.0);
375 SpinBox2_2->SetValue(0.0);
376 SpinBox2_3->SetValue(0.0);
378 ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE);
379 CheckBoxMesh->setChecked(false);
380 // MakeGroupsCheck->setChecked(false);
381 // MakeGroupsCheck->setEnabled(false);
386 //=================================================================================
387 // function : ConstructorsClicked()
388 // purpose : Radio button management
389 //=================================================================================
390 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
392 disconnect(mySelectionMgr, 0, this, 0);
394 switch (constructorId) {
397 TextLabel1->setText(tr("SMESH_POINT_1"));
398 TextLabel1_1->setText(tr("SMESH_X"));
399 TextLabel1_2->setText(tr("SMESH_Y"));
400 TextLabel1_3->setText(tr("SMESH_Z"));
402 SelectButton1->show();
404 SelectButton2->show();
405 TextLabel2_1->show();
407 TextLabel2_2->show();
409 TextLabel2_3->show();
415 TextLabel1->setText(tr("SMESH_VECTOR"));
416 TextLabel1_1->setText(tr("SMESH_DX"));
417 TextLabel1_2->setText(tr("SMESH_DY"));
418 TextLabel1_3->setText(tr("SMESH_DZ"));
420 SelectButton1->hide();
422 SelectButton2->hide();
423 TextLabel2_1->hide();
425 TextLabel2_2->hide();
427 TextLabel2_3->hide();
433 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
434 SMESH::SetPointRepresentation(false);
435 if (!CheckBoxMesh->isChecked())
436 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
437 aViewWindow->SetSelectionMode( CellSelection );
440 myEditCurrentArgument = (QWidget*)LineEditElements;
441 LineEditElements->setFocus();
443 if (CheckBoxMesh->isChecked())
446 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
449 //=================================================================================
450 // function : ClickOnApply()
452 //=================================================================================
453 void SMESHGUI_TranslationDlg::ClickOnApply()
455 if (mySMESHGUI->isActiveStudyLocked())
458 if (myNbOkElements) {
459 QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
461 SMESH::long_array_var anElementsId = new SMESH::long_array;
463 anElementsId->length(aListElementsId.count());
464 for (int i = 0; i < aListElementsId.count(); i++)
465 anElementsId[i] = aListElementsId[i].toInt();
467 SMESH::DirStruct aVector;
468 if (GetConstructorId() == 0) {
469 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
470 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
471 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
472 } else if (GetConstructorId() == 1) {
473 aVector.PS.x = SpinBox1_1->GetValue();
474 aVector.PS.y = SpinBox1_2->GetValue();
475 aVector.PS.z = SpinBox1_3->GetValue();
478 int actionButton = ActionGroup->id( ActionGroup->selected() );
479 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
481 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
482 QApplication::setOverrideCursor(Qt::waitCursor);
483 switch ( actionButton ) {
484 case MOVE_ELEMS_BUTTON:
485 aMeshEditor->Translate(anElementsId, aVector, false);
487 case COPY_ELEMS_BUTTON:
489 SMESH::ListOfGroups_var groups =
490 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
492 aMeshEditor->Translate(anElementsId, aVector, true);
494 case MAKE_MESH_BUTTON:
495 SMESH::SMESH_Mesh_var mesh =
496 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
497 LineEditNewMesh->text().latin1());
499 QApplication::restoreOverrideCursor();
504 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
505 actionButton == MAKE_MESH_BUTTON )
506 mySMESHGUI->updateObjBrowser(true); // new groups may appear
508 ConstructorsClicked(GetConstructorId());
509 SelectionIntoArgument();
513 //=================================================================================
514 // function : ClickOnOk()
516 //=================================================================================
517 void SMESHGUI_TranslationDlg::ClickOnOk()
523 //=================================================================================
524 // function : ClickOnCancel()
526 //=================================================================================
527 void SMESHGUI_TranslationDlg::ClickOnCancel()
529 disconnect(mySelectionMgr, 0, this, 0);
530 mySelectionMgr->clearFilters();
531 //mySelectionMgr->clearSelected();
532 SMESH::SetPointRepresentation(false);
533 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
534 aViewWindow->SetSelectionMode( ActorSelection );
535 mySMESHGUI->ResetState();
539 //=================================================================================
540 // function : ClickOnHelp()
542 //=================================================================================
543 void SMESHGUI_TranslationDlg::ClickOnHelp()
545 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
547 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
551 platform = "winapplication";
553 platform = "application";
555 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
556 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
557 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
558 QObject::tr("BUT_OK"));
562 //=======================================================================
563 // function : onTextChange()
565 //=======================================================================
566 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
568 QLineEdit* send = (QLineEdit*)sender();
573 if (send == LineEditElements)
576 buttonOk->setEnabled(false);
577 buttonApply->setEnabled(false);
579 // hilight entered elements
580 SMDS_Mesh* aMesh = 0;
582 aMesh = myActor->GetObject()->GetMesh();
585 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
587 TColStd_MapOfInteger newIndices;
589 QStringList aListId = QStringList::split(" ", theNewText, false);
591 if (send == LineEditElements) {
592 for (int i = 0; i < aListId.count(); i++) {
593 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
595 newIndices.Add(e->GetID());
600 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
601 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
602 aViewWindow->highlight( anIO, true, true );
604 myElementsId = theNewText;
607 if (myNbOkElements) {
608 buttonOk->setEnabled(true);
609 buttonApply->setEnabled(true);
615 //=================================================================================
616 // function : SelectionIntoArgument()
617 // purpose : Called when selection as changed or other case
618 //=================================================================================
619 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
625 QString aString = "";
628 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
629 LineEditElements->setText(aString);
631 buttonOk->setEnabled(false);
632 buttonApply->setEnabled(false);
636 if (!GroupButtons->isEnabled()) // inactive
641 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
643 int nbSel = aList.Extent();
647 Handle(SALOME_InteractiveObject) IO = aList.First();
648 myMesh = SMESH::GetMeshByIO(IO);
649 if (myMesh->_is_nil())
652 myActor = SMESH::FindActorByObject(myMesh);
654 myActor = SMESH::FindActorByEntry(IO->getEntry());
660 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
663 // MakeGroups is available if there are groups and "Copy"
664 if ( myMesh->NbGroups() == 0 ) {
665 MakeGroupsCheck->setChecked(false);
666 MakeGroupsCheck->setEnabled(false);
668 else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
669 MakeGroupsCheck->setEnabled(true);
672 if (CheckBoxMesh->isChecked()) {
673 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
675 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
677 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
681 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
682 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
684 myElementsId += QString(" %1").arg(i);
688 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
690 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
692 // get IDs from submesh
693 SMESH::long_array_var anElementsIds = new SMESH::long_array;
694 anElementsIds = aSubMesh->GetElementsId();
695 for (int i = 0; i < anElementsIds->length(); i++) {
696 myElementsId += QString(" %1").arg(anElementsIds[i]);
698 aNbUnits = anElementsIds->length();
701 SMESH::SMESH_GroupBase_var aGroup =
702 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
703 if (aGroup->_is_nil())
706 // get IDs from smesh group
707 SMESH::long_array_var anElementsIds = new SMESH::long_array;
708 anElementsIds = aGroup->GetListOfID();
709 for (int i = 0; i < anElementsIds->length(); i++) {
710 myElementsId += QString(" %1").arg(anElementsIds[i]);
712 aNbUnits = anElementsIds->length();
715 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
716 myElementsId = aString;
722 myNbOkElements = true;
724 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
728 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
732 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
740 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
741 SpinBox1_1->SetValue(x);
742 SpinBox1_2->SetValue(y);
743 SpinBox1_3->SetValue(z);
744 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
745 SpinBox2_1->SetValue(x);
746 SpinBox2_2->SetValue(y);
747 SpinBox2_3->SetValue(z);
752 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
753 LineEditElements->setText(aString);
759 if (myNbOkElements) {
760 buttonOk->setEnabled(true);
761 buttonApply->setEnabled(true);
765 //=================================================================================
766 // function : SetEditCurrentArgument()
768 //=================================================================================
769 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
771 QPushButton* send = (QPushButton*)sender();
773 disconnect(mySelectionMgr, 0, this, 0);
774 mySelectionMgr->clearSelected();
775 mySelectionMgr->clearFilters();
777 if (send == SelectElementsButton) {
778 myEditCurrentArgument = (QWidget*)LineEditElements;
779 SMESH::SetPointRepresentation(false);
780 if (CheckBoxMesh->isChecked()) {
781 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
782 aViewWindow->SetSelectionMode( ActorSelection );
783 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
786 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
787 aViewWindow->SetSelectionMode( CellSelection );
789 } else if (send == SelectButton1) {
790 myEditCurrentArgument = (QWidget*)SpinBox1_1;
791 SMESH::SetPointRepresentation(true);
793 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
794 aViewWindow->SetSelectionMode( NodeSelection );
795 } else if (send == SelectButton2) {
796 myEditCurrentArgument = (QWidget*)SpinBox2_1;
797 SMESH::SetPointRepresentation(true);
799 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
800 aViewWindow->SetSelectionMode( NodeSelection );
803 myEditCurrentArgument->setFocus();
804 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
805 SelectionIntoArgument();
808 //=================================================================================
809 // function : DeactivateActiveDialog()
811 //=================================================================================
812 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
814 if (GroupConstructors->isEnabled()) {
815 GroupConstructors->setEnabled(false);
816 GroupArguments->setEnabled(false);
817 GroupButtons->setEnabled(false);
818 mySMESHGUI->ResetState();
819 mySMESHGUI->SetActiveDialogBox(0);
823 //=================================================================================
824 // function : ActivateThisDialog()
826 //=================================================================================
827 void SMESHGUI_TranslationDlg::ActivateThisDialog()
829 /* Emit a signal to deactivate the active dialog */
830 mySMESHGUI->EmitSignalDeactivateDialog();
831 GroupConstructors->setEnabled(true);
832 GroupArguments->setEnabled(true);
833 GroupButtons->setEnabled(true);
835 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
837 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
838 aViewWindow->SetSelectionMode( CellSelection );
840 SelectionIntoArgument();
843 //=================================================================================
844 // function : enterEvent()
846 //=================================================================================
847 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
849 if (!GroupConstructors->isEnabled())
850 ActivateThisDialog();
853 //=================================================================================
854 // function : closeEvent()
856 //=================================================================================
857 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
859 /* same than click on cancel button */
860 this->ClickOnCancel();
863 //=======================================================================
864 //function : hideEvent
865 //purpose : caused by ESC key
866 //=======================================================================
867 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
873 //=======================================================================
874 //function : onSelectMesh
876 //=======================================================================
877 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
880 TextLabelElements->setText(tr("SMESH_NAME"));
882 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
884 if (myEditCurrentArgument != LineEditElements) {
885 LineEditElements->clear();
889 mySelectionMgr->clearFilters();
890 SMESH::SetPointRepresentation(false);
893 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
894 aViewWindow->SetSelectionMode( ActorSelection );
895 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
896 LineEditElements->setReadOnly(true);
898 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
899 aViewWindow->SetSelectionMode( CellSelection );
900 LineEditElements->setReadOnly(false);
901 onTextChange(LineEditElements->text());
904 SelectionIntoArgument();
907 //=======================================================================
908 //function : onActionClicked
909 //purpose : slot called when an action type changed
910 //=======================================================================
912 void SMESHGUI_TranslationDlg::onActionClicked(int button)
915 case MOVE_ELEMS_BUTTON:
916 MakeGroupsCheck->setEnabled(false);
917 LineEditNewMesh->setEnabled(false);
919 case COPY_ELEMS_BUTTON:
920 LineEditNewMesh->setEnabled(false);
921 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
922 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
923 MakeGroupsCheck->setEnabled(true);
925 MakeGroupsCheck->setEnabled(false);
927 case MAKE_MESH_BUTTON:
928 LineEditNewMesh->setEnabled(true);
929 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
930 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
931 MakeGroupsCheck->setEnabled(true);
933 MakeGroupsCheck->setEnabled(false);
939 //=======================================================================
940 //function : setNewMeshName
941 //purpose : update contents of LineEditNewMesh
942 //=======================================================================
944 void SMESHGUI_TranslationDlg::setNewMeshName()
946 LineEditNewMesh->setText("");
947 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
949 if ( CheckBoxMesh->isChecked() ) {
950 name = LineEditElements->text();
953 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
954 name = meshSO->GetName();
956 if ( !name.isEmpty() )
957 LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "translated"));
961 //=================================================================================
962 // function : GetConstructorId()
964 //=================================================================================
965 int SMESHGUI_TranslationDlg::GetConstructorId()
967 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
968 return GroupConstructors->id(GroupConstructors->selected());
972 //=================================================================================
973 // function : keyPressEvent()
975 //=================================================================================
976 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
978 QDialog::keyPressEvent( e );
979 if ( e->isAccepted() )
982 if ( e->key() == Key_F1 )