1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_TranslationDlg.cxx
24 // Author : Michael ZORIN
28 #include "SMESHGUI_TranslationDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMESH_LogicalFilter.hxx"
40 #include "SMDS_Mesh.hxx"
42 #include "SUIT_Desktop.h"
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
47 #include "LightApp_Application.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_Selection.h"
51 #include "SVTK_ViewWindow.h"
52 #include "SVTK_Selector.h"
53 #include "SALOME_ListIO.hxx"
54 #include "SALOMEDSClient_SObject.hxx"
56 #include "utilities.h"
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <qapplication.h>
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
67 #include <qlineedit.h>
68 #include <qpushbutton.h>
69 #include <qradiobutton.h>
70 #include <qcheckbox.h>
76 #include "SALOMEconfig.h"
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 \brief Simple 'busy state' flag locker.
93 //! Constructor. Sets passed boolean flag to \c true.
94 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96 ~BusyLocker() { myBusy = false; }
98 bool& myBusy; //! External 'busy state' boolean flag
101 //=================================================================================
102 // class : SMESHGUI_TranslationDlg()
104 //=================================================================================
105 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const char* name,
106 bool modal, WFlags fl)
107 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
108 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
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 setName("SMESHGUI_TranslationDlg");
119 setCaption(tr("SMESH_TRANSLATION"));
120 setSizeGripEnabled(TRUE);
121 SMESHGUI_TranslationDlgLayout = new QGridLayout(this);
122 SMESHGUI_TranslationDlgLayout->setSpacing(6);
123 SMESHGUI_TranslationDlgLayout->setMargin(11);
125 /***************************************************************/
126 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
127 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth()));
128 GroupConstructors->setTitle(tr("SMESH_TRANSLATION" ));
129 GroupConstructors->setExclusive(TRUE);
130 GroupConstructors->setColumnLayout(0, Qt::Vertical);
131 GroupConstructors->layout()->setSpacing(0);
132 GroupConstructors->layout()->setMargin(0);
133 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
134 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
135 GroupConstructorsLayout->setSpacing(6);
136 GroupConstructorsLayout->setMargin(11);
137 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
138 RadioButton1->setText(tr("" ));
139 RadioButton1->setPixmap(image0);
140 GroupConstructorsLayout->addWidget(RadioButton1, 0, 0);
141 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
142 RadioButton2->setText(tr("" ));
143 RadioButton2->setPixmap(image1);
144 GroupConstructorsLayout->addWidget(RadioButton2, 0, 2 );
145 SMESHGUI_TranslationDlgLayout->addWidget(GroupConstructors, 0, 0);
147 /***************************************************************/
148 GroupButtons = new QGroupBox(this, "GroupButtons");
149 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
150 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
151 GroupButtons->setTitle(tr("" ));
152 GroupButtons->setColumnLayout(0, Qt::Vertical);
153 GroupButtons->layout()->setSpacing(0);
154 GroupButtons->layout()->setMargin(0);
155 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
156 GroupButtonsLayout->setAlignment(Qt::AlignTop);
157 GroupButtonsLayout->setSpacing(6);
158 GroupButtonsLayout->setMargin(11);
159 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
160 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
161 buttonHelp->setAutoDefault(TRUE);
162 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
163 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
164 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
165 buttonCancel->setAutoDefault(TRUE);
166 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
167 buttonApply = new QPushButton(GroupButtons, "buttonApply");
168 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
169 buttonApply->setAutoDefault(TRUE);
170 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
171 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
172 GroupButtonsLayout->addItem(spacer_9, 0, 2);
173 buttonOk = new QPushButton(GroupButtons, "buttonOk");
174 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
175 buttonOk->setAutoDefault(TRUE);
176 buttonOk->setDefault(TRUE);
177 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
178 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons, 2, 0);
180 /***************************************************************/
181 GroupArguments = new QGroupBox(this, "GroupArguments");
182 GroupArguments->setTitle(tr("SMESH_ARGUMENTS"));
183 GroupArguments->setColumnLayout(0, Qt::Vertical);
184 GroupArguments->layout()->setSpacing(0);
185 GroupArguments->layout()->setMargin(0);
186 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
187 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
188 GroupArgumentsLayout->setSpacing(6);
189 GroupArgumentsLayout->setMargin(11);
191 // Controls for elements selection
192 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
193 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
194 TextLabelElements->setFixedWidth(74);
195 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
197 SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton");
198 SelectElementsButton->setText(tr("" ));
199 SelectElementsButton->setPixmap(image2);
200 SelectElementsButton->setToggleButton(FALSE);
201 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
203 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
204 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
205 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
207 // Control for the whole mesh selection
208 CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh");
209 CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" ));
210 GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 7);
212 // Controls for vector and points selection
213 TextLabel1 = new QLabel(GroupArguments, "TextLabel1");
214 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
216 SelectButton1 = new QPushButton(GroupArguments, "SelectButton1");
217 SelectButton1->setText(tr("" ));
218 SelectButton1->setPixmap(image2);
219 SelectButton1->setToggleButton(FALSE);
220 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
222 TextLabel1_1 = new QLabel(GroupArguments, "TextLabel1_1");
223 TextLabel1_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
224 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
226 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_1");
227 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
229 TextLabel1_2 = new QLabel(GroupArguments, "TextLabel1_2");
230 TextLabel1_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
231 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
233 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_2");
234 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
236 TextLabel1_3 = new QLabel(GroupArguments, "TextLabel1_3");
237 TextLabel1_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
238 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
240 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox1_3");
241 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
243 TextLabel2 = new QLabel(GroupArguments, "TextLabel2");
244 TextLabel2->setText(tr("SMESH_POINT_2" ));
245 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
247 SelectButton2 = new QPushButton(GroupArguments, "SelectButton2");
248 SelectButton2->setText(tr("" ));
249 SelectButton2->setPixmap(image2);
250 SelectButton2->setToggleButton(FALSE);
251 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
253 TextLabel2_1 = new QLabel(GroupArguments, "TextLabel2_1");
254 TextLabel2_1->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
255 TextLabel2_1->setText(tr("SMESH_X" ));
256 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
258 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_1");
259 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
261 TextLabel2_2 = new QLabel(GroupArguments, "TextLabel2_2");
262 TextLabel2_2->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
263 TextLabel2_2->setText(tr("SMESH_Y" ));
264 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
266 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_2");
267 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
269 TextLabel2_3 = new QLabel(GroupArguments, "TextLabel2_3");
270 TextLabel2_3->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
271 TextLabel2_3->setText(tr("SMESH_Z"));
272 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
274 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments, "SpinBox2_3");
275 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
277 // Controls for "Create a copy" option
278 // CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy");
279 // CheckBoxCopy->setText(tr("SMESH_CREATE_COPY"));
280 // GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2);
282 // switch of action type
283 ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup");
284 ActionGroup->setExclusive(true);
285 ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON);
286 ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON);
287 ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON);
288 GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 4, 6, 0, 3);
290 // CheckBox for groups generation
291 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
292 MakeGroupsCheck->setChecked(false);
293 GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 4, 7);
295 // Name of a mesh to create
296 LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh");
297 GroupArgumentsLayout->addMultiCellWidget(LineEditNewMesh, 6, 6, 4, 7);
299 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0);
301 /* Initialisations */
302 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
303 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
304 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
305 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
306 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
307 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
309 GroupArguments->show();
310 RadioButton1->setChecked(TRUE);
312 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
314 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
316 // Costruction of the logical filter
317 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
318 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
320 QPtrList<SUIT_SelectionFilter> aListOfFilters;
321 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
322 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
324 myMeshOrSubMeshOrGroupFilter =
325 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
327 myHelpFileName = "translation_page.html";
331 /* signals and slots connections */
332 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
333 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
334 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
335 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
336 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
338 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
339 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
340 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
342 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
343 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
344 /* to close dialog if study change */
345 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
346 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
347 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
348 connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int)));
350 this->show(); /* displays Dialog */
352 ConstructorsClicked(0);
353 SelectionIntoArgument();
354 onActionClicked(MOVE_ELEMS_BUTTON);
358 //=================================================================================
359 // function : ~SMESHGUI_TranslationDlg()
360 // purpose : Destroys the object and frees any allocated resources
361 //=================================================================================
362 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
364 // no need to delete child widgets, Qt does it all for us
367 //=================================================================================
370 //=================================================================================
371 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
375 myEditCurrentArgument = 0;
376 LineEditElements->clear();
380 buttonOk->setEnabled(false);
381 buttonApply->setEnabled(false);
384 myMesh = SMESH::SMESH_Mesh::_nil();
387 SpinBox1_1->SetValue(0.0);
388 SpinBox1_2->SetValue(0.0);
389 SpinBox1_3->SetValue(0.0);
390 SpinBox2_1->SetValue(0.0);
391 SpinBox2_2->SetValue(0.0);
392 SpinBox2_3->SetValue(0.0);
394 ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE);
395 CheckBoxMesh->setChecked(false);
396 // MakeGroupsCheck->setChecked(false);
397 // MakeGroupsCheck->setEnabled(false);
402 //=================================================================================
403 // function : ConstructorsClicked()
404 // purpose : Radio button management
405 //=================================================================================
406 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
408 disconnect(mySelectionMgr, 0, this, 0);
410 switch (constructorId) {
413 TextLabel1->setText(tr("SMESH_POINT_1"));
414 TextLabel1_1->setText(tr("SMESH_X"));
415 TextLabel1_2->setText(tr("SMESH_Y"));
416 TextLabel1_3->setText(tr("SMESH_Z"));
418 SelectButton1->show();
420 SelectButton2->show();
421 TextLabel2_1->show();
423 TextLabel2_2->show();
425 TextLabel2_3->show();
431 TextLabel1->setText(tr("SMESH_VECTOR"));
432 TextLabel1_1->setText(tr("SMESH_DX"));
433 TextLabel1_2->setText(tr("SMESH_DY"));
434 TextLabel1_3->setText(tr("SMESH_DZ"));
436 SelectButton1->hide();
438 SelectButton2->hide();
439 TextLabel2_1->hide();
441 TextLabel2_2->hide();
443 TextLabel2_3->hide();
449 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
450 SMESH::SetPointRepresentation(false);
451 if (!CheckBoxMesh->isChecked())
452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453 aViewWindow->SetSelectionMode( CellSelection );
456 myEditCurrentArgument = (QWidget*)LineEditElements;
457 LineEditElements->setFocus();
459 if (CheckBoxMesh->isChecked())
462 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
465 //=================================================================================
466 // function : ClickOnApply()
468 //=================================================================================
469 void SMESHGUI_TranslationDlg::ClickOnApply()
471 if (mySMESHGUI->isActiveStudyLocked() || myBusy )
473 BusyLocker lock( myBusy );
475 if (myNbOkElements) {
476 QStringList aListElementsId = QStringList::split(" ", myElementsId, false);
478 SMESH::long_array_var anElementsId = new SMESH::long_array;
480 anElementsId->length(aListElementsId.count());
481 for (int i = 0; i < aListElementsId.count(); i++)
482 anElementsId[i] = aListElementsId[i].toInt();
484 SMESH::DirStruct aVector;
485 if (GetConstructorId() == 0) {
486 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
487 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
488 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
489 } else if (GetConstructorId() == 1) {
490 aVector.PS.x = SpinBox1_1->GetValue();
491 aVector.PS.y = SpinBox1_2->GetValue();
492 aVector.PS.z = SpinBox1_3->GetValue();
495 int actionButton = ActionGroup->id( ActionGroup->selected() );
496 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
499 QApplication::setOverrideCursor(Qt::waitCursor);
500 switch ( actionButton ) {
501 case MOVE_ELEMS_BUTTON:
502 aMeshEditor->Translate(anElementsId, aVector, false);
504 case COPY_ELEMS_BUTTON:
506 SMESH::ListOfGroups_var groups =
507 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
509 aMeshEditor->Translate(anElementsId, aVector, true);
511 case MAKE_MESH_BUTTON:
512 SMESH::SMESH_Mesh_var mesh =
513 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
514 LineEditNewMesh->text().latin1());
516 QApplication::restoreOverrideCursor();
521 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
522 actionButton == MAKE_MESH_BUTTON )
523 mySMESHGUI->updateObjBrowser(true); // new groups may appear
525 ConstructorsClicked(GetConstructorId());
526 SelectionIntoArgument();
530 //=================================================================================
531 // function : ClickOnOk()
533 //=================================================================================
534 void SMESHGUI_TranslationDlg::ClickOnOk()
540 //=================================================================================
541 // function : ClickOnCancel()
543 //=================================================================================
544 void SMESHGUI_TranslationDlg::ClickOnCancel()
546 disconnect(mySelectionMgr, 0, this, 0);
547 mySelectionMgr->clearFilters();
548 //mySelectionMgr->clearSelected();
549 SMESH::SetPointRepresentation(false);
550 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
551 aViewWindow->SetSelectionMode( ActorSelection );
552 mySMESHGUI->ResetState();
556 //=================================================================================
557 // function : ClickOnHelp()
559 //=================================================================================
560 void SMESHGUI_TranslationDlg::ClickOnHelp()
562 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
564 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
568 platform = "winapplication";
570 platform = "application";
572 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
573 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
574 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
575 QObject::tr("BUT_OK"));
579 //=======================================================================
580 // function : onTextChange()
582 //=======================================================================
583 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
585 QLineEdit* send = (QLineEdit*)sender();
588 BusyLocker lock( myBusy );
590 if (send == LineEditElements)
593 buttonOk->setEnabled(false);
594 buttonApply->setEnabled(false);
596 // hilight entered elements
597 SMDS_Mesh* aMesh = 0;
599 aMesh = myActor->GetObject()->GetMesh();
602 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
604 TColStd_MapOfInteger newIndices;
606 QStringList aListId = QStringList::split(" ", theNewText, false);
608 if (send == LineEditElements) {
609 for (int i = 0; i < aListId.count(); i++) {
610 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
612 newIndices.Add(e->GetID());
617 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
618 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
619 aViewWindow->highlight( anIO, true, true );
621 myElementsId = theNewText;
624 if (myNbOkElements) {
625 buttonOk->setEnabled(true);
626 buttonApply->setEnabled(true);
631 //=================================================================================
632 // function : SelectionIntoArgument()
633 // purpose : Called when selection as changed or other case
634 //=================================================================================
635 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
639 BusyLocker lock( myBusy );
643 QString aString = "";
645 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
646 LineEditElements->setText(aString);
648 buttonOk->setEnabled(false);
649 buttonApply->setEnabled(false);
652 if (!GroupButtons->isEnabled()) // inactive
657 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
659 int nbSel = aList.Extent();
663 Handle(SALOME_InteractiveObject) IO = aList.First();
664 myMesh = SMESH::GetMeshByIO(IO);
665 if (myMesh->_is_nil())
668 myActor = SMESH::FindActorByObject(myMesh);
670 myActor = SMESH::FindActorByEntry(IO->getEntry());
676 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
679 // MakeGroups is available if there are groups and "Copy"
680 if ( myMesh->NbGroups() == 0 ) {
681 MakeGroupsCheck->setChecked(false);
682 MakeGroupsCheck->setEnabled(false);
684 else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) {
685 MakeGroupsCheck->setEnabled(true);
688 if (CheckBoxMesh->isChecked()) {
689 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
691 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
693 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
697 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
698 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
700 myElementsId += QString(" %1").arg(i);
704 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
706 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
708 // get IDs from submesh
709 SMESH::long_array_var anElementsIds = new SMESH::long_array;
710 anElementsIds = aSubMesh->GetElementsId();
711 for (int i = 0; i < anElementsIds->length(); i++) {
712 myElementsId += QString(" %1").arg(anElementsIds[i]);
714 aNbUnits = anElementsIds->length();
717 SMESH::SMESH_GroupBase_var aGroup =
718 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
719 if (aGroup->_is_nil())
722 // get IDs from smesh group
723 SMESH::long_array_var anElementsIds = new SMESH::long_array;
724 anElementsIds = aGroup->GetListOfID();
725 for (int i = 0; i < anElementsIds->length(); i++) {
726 myElementsId += QString(" %1").arg(anElementsIds[i]);
728 aNbUnits = anElementsIds->length();
731 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
732 myElementsId = aString;
738 myNbOkElements = true;
740 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
744 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
748 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
756 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
757 SpinBox1_1->SetValue(x);
758 SpinBox1_2->SetValue(y);
759 SpinBox1_3->SetValue(z);
760 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
761 SpinBox2_1->SetValue(x);
762 SpinBox2_2->SetValue(y);
763 SpinBox2_3->SetValue(z);
767 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
768 LineEditElements->setText(aString);
769 LineEditElements->repaint();
774 if (myNbOkElements) {
775 buttonOk->setEnabled(true);
776 buttonApply->setEnabled(true);
780 //=================================================================================
781 // function : SetEditCurrentArgument()
783 //=================================================================================
784 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
787 BusyLocker lock( myBusy );
789 QPushButton* send = (QPushButton*)sender();
791 disconnect(mySelectionMgr, 0, this, 0);
792 mySelectionMgr->clearSelected();
793 mySelectionMgr->clearFilters();
795 if (send == SelectElementsButton) {
796 myEditCurrentArgument = (QWidget*)LineEditElements;
797 SMESH::SetPointRepresentation(false);
798 if (CheckBoxMesh->isChecked()) {
799 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
800 aViewWindow->SetSelectionMode( ActorSelection );
801 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
804 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
805 aViewWindow->SetSelectionMode( CellSelection );
807 } else if (send == SelectButton1) {
808 myEditCurrentArgument = (QWidget*)SpinBox1_1;
809 SMESH::SetPointRepresentation(true);
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode( NodeSelection );
813 } else if (send == SelectButton2) {
814 myEditCurrentArgument = (QWidget*)SpinBox2_1;
815 SMESH::SetPointRepresentation(true);
817 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818 aViewWindow->SetSelectionMode( NodeSelection );
821 myEditCurrentArgument->setFocus();
822 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
823 SelectionIntoArgument();
826 //=================================================================================
827 // function : DeactivateActiveDialog()
829 //=================================================================================
830 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
832 if (GroupConstructors->isEnabled()) {
833 GroupConstructors->setEnabled(false);
834 GroupArguments->setEnabled(false);
835 GroupButtons->setEnabled(false);
836 mySMESHGUI->ResetState();
837 mySMESHGUI->SetActiveDialogBox(0);
841 //=================================================================================
842 // function : ActivateThisDialog()
844 //=================================================================================
845 void SMESHGUI_TranslationDlg::ActivateThisDialog()
847 /* Emit a signal to deactivate the active dialog */
848 mySMESHGUI->EmitSignalDeactivateDialog();
849 GroupConstructors->setEnabled(true);
850 GroupArguments->setEnabled(true);
851 GroupButtons->setEnabled(true);
853 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
855 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
856 aViewWindow->SetSelectionMode( CellSelection );
858 // SelectionIntoArgument();
861 //=================================================================================
862 // function : enterEvent()
864 //=================================================================================
865 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
867 if (!GroupConstructors->isEnabled())
868 ActivateThisDialog();
871 //=================================================================================
872 // function : closeEvent()
874 //=================================================================================
875 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
877 /* same than click on cancel button */
878 this->ClickOnCancel();
881 //=======================================================================
882 //function : hideEvent
883 //purpose : caused by ESC key
884 //=======================================================================
885 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
891 //=======================================================================
892 //function : onSelectMesh
894 //=======================================================================
895 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
898 TextLabelElements->setText(tr("SMESH_NAME"));
900 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
902 if (myEditCurrentArgument != LineEditElements) {
903 LineEditElements->clear();
907 mySelectionMgr->clearFilters();
908 SMESH::SetPointRepresentation(false);
911 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
912 aViewWindow->SetSelectionMode( ActorSelection );
913 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
914 LineEditElements->setReadOnly(true);
916 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
917 aViewWindow->SetSelectionMode( CellSelection );
918 LineEditElements->setReadOnly(false);
919 onTextChange(LineEditElements->text());
922 SelectionIntoArgument();
925 //=======================================================================
926 //function : onActionClicked
927 //purpose : slot called when an action type changed
928 //=======================================================================
930 void SMESHGUI_TranslationDlg::onActionClicked(int button)
933 case MOVE_ELEMS_BUTTON:
934 MakeGroupsCheck->setEnabled(false);
935 LineEditNewMesh->setEnabled(false);
937 case COPY_ELEMS_BUTTON:
938 LineEditNewMesh->setEnabled(false);
939 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
940 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
941 MakeGroupsCheck->setEnabled(true);
943 MakeGroupsCheck->setEnabled(false);
945 case MAKE_MESH_BUTTON:
946 LineEditNewMesh->setEnabled(true);
947 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
948 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
949 MakeGroupsCheck->setEnabled(true);
951 MakeGroupsCheck->setEnabled(false);
957 //=======================================================================
958 //function : setNewMeshName
959 //purpose : update contents of LineEditNewMesh
960 //=======================================================================
962 void SMESHGUI_TranslationDlg::setNewMeshName()
964 LineEditNewMesh->setText("");
965 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
967 if ( CheckBoxMesh->isChecked() ) {
968 name = LineEditElements->text();
971 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
972 name = meshSO->GetName();
974 if ( !name.isEmpty() )
975 LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "translated"));
979 //=================================================================================
980 // function : GetConstructorId()
982 //=================================================================================
983 int SMESHGUI_TranslationDlg::GetConstructorId()
985 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
986 return GroupConstructors->id(GroupConstructors->selected());
990 //=================================================================================
991 // function : keyPressEvent()
993 //=================================================================================
994 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
996 QDialog::keyPressEvent( e );
997 if ( e->isAccepted() )
1000 if ( e->key() == Key_F1 )