1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_TranslationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_TranslationDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
55 #include <SALOME_ListIteratorOfListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <TColStd_MapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
84 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 \brief Simple 'busy state' flag locker.
95 //! Constructor. Sets passed boolean flag to \c true.
96 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
97 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
98 ~BusyLocker() { myBusy = false; }
100 bool& myBusy; //! External 'busy state' boolean flag
107 //=================================================================================
108 // class : SMESHGUI_TranslationDlg()
110 //=================================================================================
111 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
112 SMESHGUI_MultiPreviewDlg( theModule ),
113 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
116 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
117 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
118 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
121 setAttribute(Qt::WA_DeleteOnClose, true);
122 setWindowTitle(tr("SMESH_TRANSLATION"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
126 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
127 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
129 /***************************************************************/
130 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
131 GroupConstructors = new QButtonGroup(this);
132 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
133 ConstructorsBoxLayout->setSpacing(SPACING);
134 ConstructorsBoxLayout->setMargin(MARGIN);
136 RadioButton1= new QRadioButton(ConstructorsBox);
137 RadioButton1->setIcon(image0);
138 RadioButton2= new QRadioButton(ConstructorsBox);
139 RadioButton2->setIcon(image1);
141 ConstructorsBoxLayout->addWidget(RadioButton1);
142 ConstructorsBoxLayout->addWidget(RadioButton2);
143 GroupConstructors->addButton(RadioButton1, 0);
144 GroupConstructors->addButton(RadioButton2, 1);
146 /***************************************************************/
147 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149 GroupArgumentsLayout->setSpacing(SPACING);
150 GroupArgumentsLayout->setMargin(MARGIN);
152 myIdValidator = new SMESHGUI_IdValidator(this);
154 // Controls for elements selection
155 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
156 SelectElementsButton = new QPushButton(GroupArguments);
157 SelectElementsButton->setIcon(image2);
158 LineEditElements = new QLineEdit(GroupArguments);
159 LineEditElements->setValidator(myIdValidator);
160 LineEditElements->setMaxLength(-1);
161 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
164 // Control for the whole mesh selection
165 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
167 // Controls for vector and points selection
168 TextLabel1 = new QLabel(GroupArguments);
169 SelectButton1 = new QPushButton(GroupArguments);
170 SelectButton1->setIcon(image2);
172 TextLabel1_1 = new QLabel(GroupArguments);
173 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_2 = new QLabel(GroupArguments);
175 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel1_3 = new QLabel(GroupArguments);
177 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
180 SelectButton2 = new QPushButton(GroupArguments);
181 SelectButton2->setIcon(image2);
183 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
184 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
186 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
187 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
188 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
190 // switch of action type
191 ActionBox = new QGroupBox(GroupArguments);
192 ActionGroup = new QButtonGroup(GroupArguments);
193 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
194 ActionBoxLayout->addSpacing(SPACING);
195 ActionBoxLayout->setMargin(MARGIN);
197 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
198 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
199 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
201 ActionBoxLayout->addWidget(aMoveElements);
202 ActionBoxLayout->addWidget(aCopyElements);
203 ActionBoxLayout->addWidget(aCreateMesh);
204 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
205 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
206 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
208 // CheckBox for groups generation
209 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
210 MakeGroupsCheck->setChecked(false);
212 // Name of a mesh to create
213 LineEditNewMesh = new QLineEdit(GroupArguments);
216 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
219 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
220 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
221 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
222 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
223 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
224 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
225 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
226 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
227 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
228 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
229 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
230 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
231 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
232 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
233 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
234 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
235 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
236 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
237 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
238 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
239 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
240 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
241 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
242 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
243 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
245 /***************************************************************/
246 GroupButtons = new QGroupBox(this);
247 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
248 GroupButtonsLayout->setSpacing(SPACING);
249 GroupButtonsLayout->setMargin(MARGIN);
251 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
252 buttonOk->setAutoDefault(true);
253 buttonOk->setDefault(true);
254 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
255 buttonApply->setAutoDefault(true);
256 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
257 buttonCancel->setAutoDefault(true);
258 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
259 buttonHelp->setAutoDefault(true);
261 GroupButtonsLayout->addWidget(buttonOk);
262 GroupButtonsLayout->addSpacing(10);
263 GroupButtonsLayout->addWidget(buttonApply);
264 GroupButtonsLayout->addSpacing(10);
265 GroupButtonsLayout->addStretch();
266 GroupButtonsLayout->addWidget(buttonCancel);
267 GroupButtonsLayout->addWidget(buttonHelp);
269 /***************************************************************/
270 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
271 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
272 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
274 /* Initialisations */
275 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
280 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
282 RadioButton1->setChecked(true);
284 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
286 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
288 // Costruction of the logical filter
289 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
290 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
292 QList<SUIT_SelectionFilter*> aListOfFilters;
293 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
294 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
296 myMeshOrSubMeshOrGroupFilter =
297 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
299 myHelpFileName = "translation_page.html";
303 /* signals and slots connections */
304 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
305 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
306 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
307 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
308 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
310 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
312 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
314 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
315 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
316 /* to close dialog if study change */
317 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
318 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
319 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
320 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
322 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox2_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox2_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox2_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
331 //To Connect preview check box
332 connectPreviewControl();
334 ConstructorsClicked(0);
335 SelectionIntoArgument();
336 onActionClicked(MOVE_ELEMS_BUTTON);
339 //=================================================================================
340 // function : ~SMESHGUI_TranslationDlg()
341 // purpose : Destroys the object and frees any allocated resources
342 //=================================================================================
343 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
346 myFilterDlg->setParent( 0 );
352 //=================================================================================
355 //=================================================================================
356 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
360 myObjectsNames.clear();
363 myEditCurrentArgument = 0;
364 LineEditElements->clear();
368 buttonOk->setEnabled(false);
369 buttonApply->setEnabled(false);
374 SpinBox1_1->SetValue(0.0);
375 SpinBox1_2->SetValue(0.0);
376 SpinBox1_3->SetValue(0.0);
377 SpinBox2_1->SetValue(0.0);
378 SpinBox2_2->SetValue(0.0);
379 SpinBox2_3->SetValue(0.0);
381 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
382 CheckBoxMesh->setChecked(false);
383 // MakeGroupsCheck->setChecked(false);
384 // MakeGroupsCheck->setEnabled(false);
385 myPreviewCheckBox->setChecked(false);
386 onDisplaySimulation(false);
391 //=================================================================================
392 // function : ConstructorsClicked()
393 // purpose : Radio button management
394 //=================================================================================
395 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
397 disconnect(mySelectionMgr, 0, this, 0);
399 switch (constructorId) {
402 TextLabel1->setText(tr("SMESH_POINT_1"));
403 TextLabel1_1->setText(tr("SMESH_X"));
404 TextLabel1_2->setText(tr("SMESH_Y"));
405 TextLabel1_3->setText(tr("SMESH_Z"));
407 SelectButton1->show();
409 SelectButton2->show();
410 TextLabel2_1->show();
412 TextLabel2_2->show();
414 TextLabel2_3->show();
420 TextLabel1->setText(tr("SMESH_VECTOR"));
421 TextLabel1_1->setText(tr("SMESH_DX"));
422 TextLabel1_2->setText(tr("SMESH_DY"));
423 TextLabel1_3->setText(tr("SMESH_DZ"));
425 SelectButton1->hide();
427 SelectButton2->hide();
428 TextLabel2_1->hide();
430 TextLabel2_2->hide();
432 TextLabel2_3->hide();
438 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
439 SMESH::SetPointRepresentation(false);
440 if (!CheckBoxMesh->isChecked())
441 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
442 aViewWindow->SetSelectionMode( CellSelection );
445 myEditCurrentArgument = (QWidget*)LineEditElements;
446 LineEditElements->setFocus();
448 if (CheckBoxMesh->isChecked())
451 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
453 onDisplaySimulation(true);
454 myEditCurrentArgument->hide();
455 myEditCurrentArgument->show();
456 QApplication::instance()->processEvents();
461 //=================================================================================
462 // function : ClickOnApply()
464 //=================================================================================
465 bool SMESHGUI_TranslationDlg::ClickOnApply()
467 if (mySMESHGUI->isActiveStudyLocked())
473 if (myNbOkElements) {
474 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
476 SMESH::long_array_var anElementsId = new SMESH::long_array;
478 anElementsId->length(aListElementsId.count());
479 for (int i = 0; i < aListElementsId.count(); i++)
480 anElementsId[i] = aListElementsId[i].toInt();
482 SMESH::DirStruct aVector;
483 QStringList aParameters;
484 if (GetConstructorId() == 0) {
485 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
486 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
487 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
488 // not supported so far
489 // aParameters << QString("%1 - %2").arg( SpinBox2_1->text() ).arg( SpinBox1_1->text() );
490 // aParameters << QString("%1 - %2").arg( SpinBox2_2->text() ).arg( SpinBox1_2->text() );
491 // aParameters << QString("%1 - %2").arg( SpinBox2_3->text() ).arg( SpinBox1_3->text() );
492 } else if (GetConstructorId() == 1) {
493 aVector.PS.x = SpinBox1_1->GetValue();
494 aVector.PS.y = SpinBox1_2->GetValue();
495 aVector.PS.z = SpinBox1_3->GetValue();
496 aParameters << SpinBox1_1->text();
497 aParameters << SpinBox1_2->text();
498 aParameters << SpinBox1_3->text();
501 int actionButton = ActionGroup->checkedId();
502 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
503 QStringList anEntryList;
505 SUIT_OverrideCursor aWaitCursor;
507 switch ( actionButton ) {
508 case MOVE_ELEMS_BUTTON:
509 if(CheckBoxMesh->isChecked())
510 for ( int i = 0; i < myObjects.count(); i++ ) {
511 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
512 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
513 aMeshEditor->TranslateObject(myObjects[i], aVector, false);
516 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
517 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
518 aMeshEditor->Translate(anElementsId, aVector, false);
521 case COPY_ELEMS_BUTTON:
523 SMESH::ListOfGroups_var groups;
524 if(CheckBoxMesh->isChecked()) {
525 for ( int i = 0; i < myObjects.count(); i++ ) {
526 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
527 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
528 groups = aMeshEditor->TranslateObjectMakeGroups(myObjects[i],aVector);
532 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
533 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
534 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
538 if(CheckBoxMesh->isChecked()) {
539 for ( int i = 0; i < myObjects.count(); i++ ) {
540 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
541 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
542 aMeshEditor->TranslateObject(myObjects[i], aVector, true);
546 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
547 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
548 aMeshEditor->Translate(anElementsId, aVector, true);
552 case MAKE_MESH_BUTTON: {
553 SMESH::SMESH_Mesh_var mesh;
554 if (CheckBoxMesh->isChecked()) {
555 for ( int i = 0; i < myObjects.count(); i++ ) {
556 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
557 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
558 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
559 mesh = aMeshEditor->TranslateObjectMakeMesh(myObjects[i], aVector, makeGroups,
560 aName.toLatin1().data());
561 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
562 anEntryList.append( aSObject->GetID().c_str() );
566 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
567 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
568 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
569 LineEditNewMesh->text().toLatin1().data());
570 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
571 anEntryList.append( aSObject->GetID().c_str() );
579 for ( int i = 0; i < myObjects.count(); i++ ) {
580 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
581 if ( actor ) SMESH::Update( actor->getIO(), true );
584 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
585 actionButton == MAKE_MESH_BUTTON ) {
586 mySMESHGUI->updateObjBrowser(true); // new groups may appear
587 if( LightApp_Application* anApp =
588 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
589 anApp->browseObjects( anEntryList, isApplyAndClose() );
593 ConstructorsClicked(GetConstructorId());
594 SelectionIntoArgument();
596 SMESHGUI::Modified();
602 //=================================================================================
603 // function : ClickOnOk()
605 //=================================================================================
606 void SMESHGUI_TranslationDlg::ClickOnOk()
608 setIsApplyAndClose( true );
613 //=================================================================================
614 // function : reject()
616 //=================================================================================
617 void SMESHGUI_TranslationDlg::reject()
619 disconnect(mySelectionMgr, 0, this, 0);
620 mySelectionMgr->clearFilters();
621 //mySelectionMgr->clearSelected();
622 if (SMESH::GetCurrentVtkView()) {
623 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
624 SMESH::SetPointRepresentation(false);
626 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
627 aViewWindow->SetSelectionMode( ActorSelection );
628 mySMESHGUI->ResetState();
632 //=================================================================================
633 // function : ClickOnHelp()
635 //=================================================================================
636 void SMESHGUI_TranslationDlg::ClickOnHelp()
638 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
640 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
644 platform = "winapplication";
646 platform = "application";
648 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
649 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
650 arg(app->resourceMgr()->stringValue("ExternalBrowser",
652 arg(myHelpFileName));
656 //=======================================================================
657 // function : onTextChange()
659 //=======================================================================
660 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
662 QLineEdit* send = (QLineEdit*)sender();
665 BusyLocker lock( myBusy );
667 if (send == LineEditElements)
670 buttonOk->setEnabled(false);
671 buttonApply->setEnabled(false);
673 // hilight entered elements
674 SMDS_Mesh* aMesh = 0;
676 aMesh = myActor->GetObject()->GetMesh();
679 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
681 TColStd_MapOfInteger newIndices;
683 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
685 if (send == LineEditElements) {
686 for (int i = 0; i < aListId.count(); i++) {
687 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
689 newIndices.Add(e->GetID());
694 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->highlight( anIO, true, true );
698 myElementsId = theNewText;
701 if (myNbOkElements) {
702 buttonOk->setEnabled(true);
703 buttonApply->setEnabled(true);
707 //=================================================================================
708 // function : SelectionIntoArgument()
709 // purpose : Called when selection as changed or other case
710 //=================================================================================
711 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
714 BusyLocker lock( myBusy );
717 QString aString = "";
718 onDisplaySimulation(false);
720 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
721 LineEditElements->setText(aString);
723 buttonOk->setEnabled(false);
724 buttonApply->setEnabled(false);
727 if (!GroupButtons->isEnabled()) // inactive
732 mySelectionMgr->selectedObjects(aList);
734 int nbSel = aList.Extent();
739 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
742 myObjectsNames.clear();
745 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
746 Handle(SALOME_InteractiveObject) IO = it.Value();
747 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
748 if ( aMesh->_is_nil() )
751 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
753 anActor = SMESH::FindActorByEntry( IO->getEntry() );
755 if ( !anActor && !CheckBoxMesh->isChecked() )
758 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
759 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
760 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
761 _PTR(GenericAttribute) anAttr;
762 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
763 _PTR(AttributeName) aNameAttr( anAttr );
764 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
765 myObjectsNames << aNameAttr->Value().c_str();
774 // MakeGroups is available if there are groups and "Copy"
776 for ( int i = 0; i < myMeshes.count(); i++ )
777 aNbGroups += myMeshes[i]->NbGroups();
779 if ( aNbGroups == 0 ) {
780 MakeGroupsCheck->setChecked(false);
781 MakeGroupsCheck->setEnabled(false);
783 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
784 MakeGroupsCheck->setEnabled(true);
787 if (CheckBoxMesh->isChecked()) {
788 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
789 if (myMeshes.isEmpty())
792 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
793 myElementsId = aString;
798 myNbOkElements = true;
800 Handle(SALOME_InteractiveObject) IO = aList.First();
801 if ((SMESH::GetMeshByIO(IO))->_is_nil())
804 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
806 anActor = SMESH::FindActorByEntry(IO->getEntry());
807 if (!anActor && !CheckBoxMesh->isChecked())
810 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
814 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
818 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
826 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
827 SpinBox1_1->SetValue(x);
828 SpinBox1_2->SetValue(y);
829 SpinBox1_3->SetValue(z);
830 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
831 SpinBox2_1->SetValue(x);
832 SpinBox2_2->SetValue(y);
833 SpinBox2_3->SetValue(z);
837 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
838 LineEditElements->setText(aString);
839 LineEditElements->repaint();
840 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
841 LineEditElements->setEnabled(true);
846 if (myNbOkElements) {
847 buttonOk->setEnabled(true);
848 buttonApply->setEnabled(true);
850 onDisplaySimulation(true);
853 //=================================================================================
854 // function : SetEditCurrentArgument()
856 //=================================================================================
857 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
859 QPushButton* send = (QPushButton*)sender();
861 disconnect(mySelectionMgr, 0, this, 0);
862 mySelectionMgr->clearSelected();
863 mySelectionMgr->clearFilters();
865 if (send == SelectElementsButton) {
866 myEditCurrentArgument = (QWidget*)LineEditElements;
867 SMESH::SetPointRepresentation(false);
868 if (CheckBoxMesh->isChecked()) {
869 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
870 aViewWindow->SetSelectionMode( ActorSelection );
871 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
874 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
875 aViewWindow->SetSelectionMode( CellSelection );
877 } else if (send == SelectButton1) {
878 myEditCurrentArgument = (QWidget*)SpinBox1_1;
879 SMESH::SetPointRepresentation(true);
881 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882 aViewWindow->SetSelectionMode( NodeSelection );
883 } else if (send == SelectButton2) {
884 myEditCurrentArgument = (QWidget*)SpinBox2_1;
885 SMESH::SetPointRepresentation(true);
887 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
888 aViewWindow->SetSelectionMode( NodeSelection );
891 myEditCurrentArgument->setFocus();
892 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
893 SelectionIntoArgument();
896 //=================================================================================
897 // function : DeactivateActiveDialog()
899 //=================================================================================
900 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
902 if (ConstructorsBox->isEnabled()) {
903 ConstructorsBox->setEnabled(false);
904 GroupArguments->setEnabled(false);
905 GroupButtons->setEnabled(false);
906 mySMESHGUI->ResetState();
907 mySMESHGUI->SetActiveDialogBox(0);
911 //=================================================================================
912 // function : ActivateThisDialog()
914 //=================================================================================
915 void SMESHGUI_TranslationDlg::ActivateThisDialog()
917 /* Emit a signal to deactivate the active dialog */
918 mySMESHGUI->EmitSignalDeactivateDialog();
919 ConstructorsBox->setEnabled(true);
920 GroupArguments->setEnabled(true);
921 GroupButtons->setEnabled(true);
923 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
925 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
926 aViewWindow->SetSelectionMode( CellSelection );
928 SelectionIntoArgument();
931 //=================================================================================
932 // function : enterEvent()
934 //=================================================================================
935 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
937 if (!ConstructorsBox->isEnabled())
938 ActivateThisDialog();
941 //=======================================================================
942 //function : onSelectMesh
944 //=======================================================================
945 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
948 TextLabelElements->setText(tr("SMESH_NAME"));
950 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
951 myFilterBtn->setEnabled(!toSelectMesh);
953 if (myEditCurrentArgument != LineEditElements) {
954 LineEditElements->clear();
958 mySelectionMgr->clearFilters();
959 SMESH::SetPointRepresentation(false);
962 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
963 aViewWindow->SetSelectionMode( ActorSelection );
964 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
965 LineEditElements->setReadOnly(true);
966 LineEditElements->setValidator(0);
968 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
969 aViewWindow->SetSelectionMode( CellSelection );
970 LineEditElements->setReadOnly(false);
971 LineEditElements->setValidator(myIdValidator);
972 onTextChange(LineEditElements->text());
976 SelectionIntoArgument();
979 //=======================================================================
980 //function : onActionClicked
981 //purpose : slot called when an action type changed
982 //=======================================================================
984 void SMESHGUI_TranslationDlg::onActionClicked(int button)
987 for ( int i = 0; i < myMeshes.count(); i++ )
988 aNbGroups += myMeshes[i]->NbGroups();
991 case MOVE_ELEMS_BUTTON:
992 MakeGroupsCheck->setEnabled(false);
993 LineEditNewMesh->setEnabled(false);
995 case COPY_ELEMS_BUTTON:
996 LineEditNewMesh->setEnabled(false);
997 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
998 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1000 case MAKE_MESH_BUTTON:
1001 LineEditNewMesh->setEnabled(true);
1002 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1003 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1007 toDisplaySimulation();
1010 //=======================================================================
1011 //function : setNewMeshName
1012 //purpose : update contents of LineEditNewMesh
1013 //=======================================================================
1015 void SMESHGUI_TranslationDlg::setNewMeshName()
1017 LineEditNewMesh->setText("");
1018 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1020 if ( CheckBoxMesh->isChecked() ) {
1021 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1024 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1025 name = meshSO->GetName().c_str();
1027 if ( !name.isEmpty() )
1028 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1032 //=================================================================================
1033 // function : GetConstructorId()
1035 //=================================================================================
1036 int SMESHGUI_TranslationDlg::GetConstructorId()
1038 return GroupConstructors->checkedId();
1041 //=================================================================================
1042 // function : keyPressEvent()
1044 //=================================================================================
1045 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1047 QDialog::keyPressEvent( e );
1048 if ( e->isAccepted() )
1051 if ( e->key() == Qt::Key_F1 ) {
1057 //=================================================================================
1058 // function : setFilters()
1059 // purpose : SLOT. Called when "Filter" button pressed.
1060 //=================================================================================
1061 void SMESHGUI_TranslationDlg::setFilters()
1063 if(myMeshes.isEmpty()) {
1064 SUIT_MessageBox::critical(this,
1066 tr("NO_MESH_SELECTED"));
1070 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1072 myFilterDlg->SetSelection();
1073 myFilterDlg->SetMesh( myMeshes[0] );
1074 myFilterDlg->SetSourceWg( LineEditElements );
1076 myFilterDlg->show();
1079 //=================================================================================
1080 // function : isValid
1082 //=================================================================================
1083 bool SMESHGUI_TranslationDlg::isValid()
1088 ok = SpinBox1_1->isValid( msg, true ) && ok;
1089 ok = SpinBox1_2->isValid( msg, true ) && ok;
1090 ok = SpinBox1_3->isValid( msg, true ) && ok;
1091 if (GetConstructorId() == 0) {
1092 ok = SpinBox2_1->isValid( msg, true ) && ok;
1093 ok = SpinBox2_2->isValid( msg, true ) && ok;
1094 ok = SpinBox2_3->isValid( msg, true ) && ok;
1098 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1099 if ( !msg.isEmpty() )
1101 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1107 //=================================================================================
1108 // function : onDisplaySimulation
1109 // purpose : Show/Hide preview
1110 //=================================================================================
1111 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1112 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1114 if (isValid() && myNbOkElements) {
1115 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1117 SMESH::long_array_var anElementsId = new SMESH::long_array;
1119 anElementsId->length(aListElementsId.count());
1120 for (int i = 0; i < aListElementsId.count(); i++)
1121 anElementsId[i] = aListElementsId[i].toInt();
1123 SMESH::DirStruct aVector;
1124 if (GetConstructorId() == 0) {
1125 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1126 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1127 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1128 } else if (GetConstructorId() == 1) {
1129 aVector.PS.x = SpinBox1_1->GetValue();
1130 aVector.PS.y = SpinBox1_2->GetValue();
1131 aVector.PS.z = SpinBox1_3->GetValue();
1135 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1136 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1137 SUIT_OverrideCursor aWaitCursor;
1138 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1139 if(CheckBoxMesh->isChecked())
1140 for ( int i = 0; i < myObjects.count(); i++ ) {
1141 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1142 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1143 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1146 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1147 aMeshEditor->Translate(anElementsId, aVector, copy);
1148 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1150 setSimulationPreview( aMeshPreviewStruct );