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>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient.hxx>
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 \brief Simple 'busy state' flag locker.
94 //! Constructor. Sets passed boolean flag to \c true.
95 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
96 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
97 ~BusyLocker() { myBusy = false; }
99 bool& myBusy; //! External 'busy state' boolean flag
106 //=================================================================================
107 // class : SMESHGUI_TranslationDlg()
109 //=================================================================================
110 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
111 SMESHGUI_MultiPreviewDlg( theModule ),
112 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
115 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
116 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
117 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setAttribute(Qt::WA_DeleteOnClose, true);
121 setWindowTitle(tr("SMESH_TRANSLATION"));
122 setSizeGripEnabled(true);
124 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
125 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
126 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
128 /***************************************************************/
129 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
130 GroupConstructors = new QButtonGroup(this);
131 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132 ConstructorsBoxLayout->setSpacing(SPACING);
133 ConstructorsBoxLayout->setMargin(MARGIN);
135 RadioButton1= new QRadioButton(ConstructorsBox);
136 RadioButton1->setIcon(image0);
137 RadioButton2= new QRadioButton(ConstructorsBox);
138 RadioButton2->setIcon(image1);
140 ConstructorsBoxLayout->addWidget(RadioButton1);
141 ConstructorsBoxLayout->addWidget(RadioButton2);
142 GroupConstructors->addButton(RadioButton1, 0);
143 GroupConstructors->addButton(RadioButton2, 1);
145 /***************************************************************/
146 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148 GroupArgumentsLayout->setSpacing(SPACING);
149 GroupArgumentsLayout->setMargin(MARGIN);
151 myIdValidator = new SMESHGUI_IdValidator(this);
153 // Controls for elements selection
154 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155 SelectElementsButton = new QPushButton(GroupArguments);
156 SelectElementsButton->setIcon(image2);
157 LineEditElements = new QLineEdit(GroupArguments);
158 LineEditElements->setValidator(myIdValidator);
159 LineEditElements->setMaxLength(-1);
160 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
163 // Control for the whole mesh selection
164 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
166 // Controls for vector and points selection
167 TextLabel1 = new QLabel(GroupArguments);
168 SelectButton1 = new QPushButton(GroupArguments);
169 SelectButton1->setIcon(image2);
171 TextLabel1_1 = new QLabel(GroupArguments);
172 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_2 = new QLabel(GroupArguments);
174 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel1_3 = new QLabel(GroupArguments);
176 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
179 SelectButton2 = new QPushButton(GroupArguments);
180 SelectButton2->setIcon(image2);
182 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
183 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
185 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
186 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
187 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
189 // switch of action type
190 ActionBox = new QGroupBox(GroupArguments);
191 ActionGroup = new QButtonGroup(GroupArguments);
192 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193 ActionBoxLayout->addSpacing(SPACING);
194 ActionBoxLayout->setMargin(MARGIN);
196 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
200 ActionBoxLayout->addWidget(aMoveElements);
201 ActionBoxLayout->addWidget(aCopyElements);
202 ActionBoxLayout->addWidget(aCreateMesh);
203 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
207 // CheckBox for groups generation
208 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209 MakeGroupsCheck->setChecked(false);
211 // Name of a mesh to create
212 LineEditNewMesh = new QLineEdit(GroupArguments);
215 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
221 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
223 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
224 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
225 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
226 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
227 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
228 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
229 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
230 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
231 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
232 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
233 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
234 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
235 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
236 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
237 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
238 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
239 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
240 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
241 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
242 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
244 /***************************************************************/
245 GroupButtons = new QGroupBox(this);
246 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247 GroupButtonsLayout->setSpacing(SPACING);
248 GroupButtonsLayout->setMargin(MARGIN);
250 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251 buttonOk->setAutoDefault(true);
252 buttonOk->setDefault(true);
253 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254 buttonApply->setAutoDefault(true);
255 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256 buttonCancel->setAutoDefault(true);
257 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258 buttonHelp->setAutoDefault(true);
260 GroupButtonsLayout->addWidget(buttonOk);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addWidget(buttonApply);
263 GroupButtonsLayout->addSpacing(10);
264 GroupButtonsLayout->addStretch();
265 GroupButtonsLayout->addWidget(buttonCancel);
266 GroupButtonsLayout->addWidget(buttonHelp);
268 /***************************************************************/
269 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
270 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
271 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
273 /* Initialisations */
274 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "translation_page.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox2_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox2_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox2_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 //To Connect preview check box
331 connectPreviewControl();
333 ConstructorsClicked(0);
334 SelectionIntoArgument();
335 onActionClicked(MOVE_ELEMS_BUTTON);
338 //=================================================================================
339 // function : ~SMESHGUI_TranslationDlg()
340 // purpose : Destroys the object and frees any allocated resources
341 //=================================================================================
342 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
345 myFilterDlg->setParent( 0 );
351 //=================================================================================
354 //=================================================================================
355 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
359 myObjectsNames.clear();
362 myEditCurrentArgument = 0;
363 LineEditElements->clear();
367 buttonOk->setEnabled(false);
368 buttonApply->setEnabled(false);
373 SpinBox1_1->SetValue(0.0);
374 SpinBox1_2->SetValue(0.0);
375 SpinBox1_3->SetValue(0.0);
376 SpinBox2_1->SetValue(0.0);
377 SpinBox2_2->SetValue(0.0);
378 SpinBox2_3->SetValue(0.0);
380 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
381 CheckBoxMesh->setChecked(false);
382 // MakeGroupsCheck->setChecked(false);
383 // MakeGroupsCheck->setEnabled(false);
384 myPreviewCheckBox->setChecked(false);
385 onDisplaySimulation(false);
390 //=================================================================================
391 // function : ConstructorsClicked()
392 // purpose : Radio button management
393 //=================================================================================
394 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
396 disconnect(mySelectionMgr, 0, this, 0);
398 switch (constructorId) {
401 TextLabel1->setText(tr("SMESH_POINT_1"));
402 TextLabel1_1->setText(tr("SMESH_X"));
403 TextLabel1_2->setText(tr("SMESH_Y"));
404 TextLabel1_3->setText(tr("SMESH_Z"));
406 SelectButton1->show();
408 SelectButton2->show();
409 TextLabel2_1->show();
411 TextLabel2_2->show();
413 TextLabel2_3->show();
419 TextLabel1->setText(tr("SMESH_VECTOR"));
420 TextLabel1_1->setText(tr("SMESH_DX"));
421 TextLabel1_2->setText(tr("SMESH_DY"));
422 TextLabel1_3->setText(tr("SMESH_DZ"));
424 SelectButton1->hide();
426 SelectButton2->hide();
427 TextLabel2_1->hide();
429 TextLabel2_2->hide();
431 TextLabel2_3->hide();
437 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
438 SMESH::SetPointRepresentation(false);
439 if (!CheckBoxMesh->isChecked())
440 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
441 aViewWindow->SetSelectionMode( CellSelection );
444 myEditCurrentArgument = (QWidget*)LineEditElements;
445 LineEditElements->setFocus();
447 if (CheckBoxMesh->isChecked())
450 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
452 onDisplaySimulation(true);
453 myEditCurrentArgument->hide();
454 myEditCurrentArgument->show();
455 QApplication::instance()->processEvents();
460 //=================================================================================
461 // function : ClickOnApply()
463 //=================================================================================
464 bool SMESHGUI_TranslationDlg::ClickOnApply()
466 if (mySMESHGUI->isActiveStudyLocked())
472 if (myNbOkElements) {
473 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
475 SMESH::long_array_var anElementsId = new SMESH::long_array;
477 anElementsId->length(aListElementsId.count());
478 for (int i = 0; i < aListElementsId.count(); i++)
479 anElementsId[i] = aListElementsId[i].toInt();
481 SMESH::DirStruct aVector;
482 QStringList aParameters;
483 if (GetConstructorId() == 0) {
484 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
485 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
486 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
487 // not supported so far
488 // aParameters << QString("%1 - %2").arg( SpinBox2_1->text() ).arg( SpinBox1_1->text() );
489 // aParameters << QString("%1 - %2").arg( SpinBox2_2->text() ).arg( SpinBox1_2->text() );
490 // aParameters << QString("%1 - %2").arg( SpinBox2_3->text() ).arg( SpinBox1_3->text() );
491 } else if (GetConstructorId() == 1) {
492 aVector.PS.x = SpinBox1_1->GetValue();
493 aVector.PS.y = SpinBox1_2->GetValue();
494 aVector.PS.z = SpinBox1_3->GetValue();
495 aParameters << SpinBox1_1->text();
496 aParameters << SpinBox1_2->text();
497 aParameters << SpinBox1_3->text();
500 int actionButton = ActionGroup->checkedId();
501 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
502 QStringList anEntryList;
504 SUIT_OverrideCursor aWaitCursor;
506 switch ( actionButton ) {
507 case MOVE_ELEMS_BUTTON:
508 if(CheckBoxMesh->isChecked())
509 for ( int i = 0; i < myObjects.count(); i++ ) {
510 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
511 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
512 aMeshEditor->TranslateObject(myObjects[i], aVector, false);
515 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
516 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
517 aMeshEditor->Translate(anElementsId, aVector, false);
520 case COPY_ELEMS_BUTTON:
522 SMESH::ListOfGroups_var groups;
523 if(CheckBoxMesh->isChecked()) {
524 for ( int i = 0; i < myObjects.count(); i++ ) {
525 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
526 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
527 groups = aMeshEditor->TranslateObjectMakeGroups(myObjects[i],aVector);
531 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
532 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
533 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
537 if(CheckBoxMesh->isChecked()) {
538 for ( int i = 0; i < myObjects.count(); i++ ) {
539 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
540 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
541 aMeshEditor->TranslateObject(myObjects[i], aVector, true);
545 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
546 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
547 aMeshEditor->Translate(anElementsId, aVector, true);
551 case MAKE_MESH_BUTTON: {
552 SMESH::SMESH_Mesh_var mesh;
553 if (CheckBoxMesh->isChecked()) {
554 for ( int i = 0; i < myObjects.count(); i++ ) {
555 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
556 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
557 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
558 mesh = aMeshEditor->TranslateObjectMakeMesh(myObjects[i], aVector, makeGroups,
559 aName.toLatin1().data());
560 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
561 anEntryList.append( aSObject->GetID().c_str() );
565 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
566 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
567 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
568 LineEditNewMesh->text().toLatin1().data());
569 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
570 anEntryList.append( aSObject->GetID().c_str() );
578 for ( int i = 0; i < myObjects.count(); i++ ) {
579 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
580 if ( actor ) SMESH::Update( actor->getIO(), true );
583 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
584 actionButton == MAKE_MESH_BUTTON ) {
585 mySMESHGUI->updateObjBrowser(true); // new groups may appear
586 if( LightApp_Application* anApp =
587 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
588 anApp->browseObjects( anEntryList, isApplyAndClose() );
592 ConstructorsClicked(GetConstructorId());
593 SelectionIntoArgument();
595 SMESHGUI::Modified();
601 //=================================================================================
602 // function : ClickOnOk()
604 //=================================================================================
605 void SMESHGUI_TranslationDlg::ClickOnOk()
607 setIsApplyAndClose( true );
612 //=================================================================================
613 // function : reject()
615 //=================================================================================
616 void SMESHGUI_TranslationDlg::reject()
618 disconnect(mySelectionMgr, 0, this, 0);
619 mySelectionMgr->clearFilters();
620 //mySelectionMgr->clearSelected();
621 if (SMESH::GetCurrentVtkView()) {
622 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
623 SMESH::SetPointRepresentation(false);
625 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626 aViewWindow->SetSelectionMode( ActorSelection );
627 mySMESHGUI->ResetState();
631 //=================================================================================
632 // function : ClickOnHelp()
634 //=================================================================================
635 void SMESHGUI_TranslationDlg::ClickOnHelp()
637 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
639 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
643 platform = "winapplication";
645 platform = "application";
647 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
648 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
649 arg(app->resourceMgr()->stringValue("ExternalBrowser",
651 arg(myHelpFileName));
655 //=======================================================================
656 // function : onTextChange()
658 //=======================================================================
659 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
661 QLineEdit* send = (QLineEdit*)sender();
664 BusyLocker lock( myBusy );
666 if (send == LineEditElements)
669 buttonOk->setEnabled(false);
670 buttonApply->setEnabled(false);
672 // hilight entered elements
673 SMDS_Mesh* aMesh = 0;
675 aMesh = myActor->GetObject()->GetMesh();
678 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
680 TColStd_MapOfInteger newIndices;
682 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
684 if (send == LineEditElements) {
685 for (int i = 0; i < aListId.count(); i++) {
686 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
688 newIndices.Add(e->GetID());
693 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
694 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
695 aViewWindow->highlight( anIO, true, true );
697 myElementsId = theNewText;
700 if (myNbOkElements) {
701 buttonOk->setEnabled(true);
702 buttonApply->setEnabled(true);
706 //=================================================================================
707 // function : SelectionIntoArgument()
708 // purpose : Called when selection as changed or other case
709 //=================================================================================
710 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
713 BusyLocker lock( myBusy );
716 QString aString = "";
717 onDisplaySimulation(false);
719 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
720 LineEditElements->setText(aString);
722 buttonOk->setEnabled(false);
723 buttonApply->setEnabled(false);
726 if (!GroupButtons->isEnabled()) // inactive
731 mySelectionMgr->selectedObjects(aList);
733 int nbSel = aList.Extent();
738 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
741 myObjectsNames.clear();
744 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
745 Handle(SALOME_InteractiveObject) IO = it.Value();
746 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
747 if ( aMesh->_is_nil() )
750 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
752 anActor = SMESH::FindActorByEntry( IO->getEntry() );
754 if ( !anActor && !CheckBoxMesh->isChecked() )
757 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
758 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
759 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
760 _PTR(GenericAttribute) anAttr;
761 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
762 _PTR(AttributeName) aNameAttr( anAttr );
763 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
764 myObjectsNames << aNameAttr->Value().c_str();
773 // MakeGroups is available if there are groups and "Copy"
775 for ( int i = 0; i < myMeshes.count(); i++ )
776 aNbGroups += myMeshes[i]->NbGroups();
778 if ( aNbGroups == 0 ) {
779 MakeGroupsCheck->setChecked(false);
780 MakeGroupsCheck->setEnabled(false);
782 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
783 MakeGroupsCheck->setEnabled(true);
786 if (CheckBoxMesh->isChecked()) {
787 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
788 if (myMeshes.isEmpty())
791 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
792 myElementsId = aString;
797 myNbOkElements = true;
799 Handle(SALOME_InteractiveObject) IO = aList.First();
800 if ((SMESH::GetMeshByIO(IO))->_is_nil())
803 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
805 anActor = SMESH::FindActorByEntry(IO->getEntry());
806 if (!anActor && !CheckBoxMesh->isChecked())
809 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
813 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
817 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
825 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
826 SpinBox1_1->SetValue(x);
827 SpinBox1_2->SetValue(y);
828 SpinBox1_3->SetValue(z);
829 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
830 SpinBox2_1->SetValue(x);
831 SpinBox2_2->SetValue(y);
832 SpinBox2_3->SetValue(z);
836 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
837 LineEditElements->setText(aString);
838 LineEditElements->repaint();
839 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
840 LineEditElements->setEnabled(true);
845 if (myNbOkElements) {
846 buttonOk->setEnabled(true);
847 buttonApply->setEnabled(true);
849 onDisplaySimulation(true);
852 //=================================================================================
853 // function : SetEditCurrentArgument()
855 //=================================================================================
856 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
858 QPushButton* send = (QPushButton*)sender();
860 disconnect(mySelectionMgr, 0, this, 0);
861 mySelectionMgr->clearSelected();
862 mySelectionMgr->clearFilters();
864 if (send == SelectElementsButton) {
865 myEditCurrentArgument = (QWidget*)LineEditElements;
866 SMESH::SetPointRepresentation(false);
867 if (CheckBoxMesh->isChecked()) {
868 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
869 aViewWindow->SetSelectionMode( ActorSelection );
870 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
873 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
874 aViewWindow->SetSelectionMode( CellSelection );
876 } else if (send == SelectButton1) {
877 myEditCurrentArgument = (QWidget*)SpinBox1_1;
878 SMESH::SetPointRepresentation(true);
880 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
881 aViewWindow->SetSelectionMode( NodeSelection );
882 } else if (send == SelectButton2) {
883 myEditCurrentArgument = (QWidget*)SpinBox2_1;
884 SMESH::SetPointRepresentation(true);
886 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
887 aViewWindow->SetSelectionMode( NodeSelection );
890 myEditCurrentArgument->setFocus();
891 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
892 SelectionIntoArgument();
895 //=================================================================================
896 // function : DeactivateActiveDialog()
898 //=================================================================================
899 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
901 if (ConstructorsBox->isEnabled()) {
902 ConstructorsBox->setEnabled(false);
903 GroupArguments->setEnabled(false);
904 GroupButtons->setEnabled(false);
905 mySMESHGUI->ResetState();
906 mySMESHGUI->SetActiveDialogBox(0);
910 //=================================================================================
911 // function : ActivateThisDialog()
913 //=================================================================================
914 void SMESHGUI_TranslationDlg::ActivateThisDialog()
916 /* Emit a signal to deactivate the active dialog */
917 mySMESHGUI->EmitSignalDeactivateDialog();
918 ConstructorsBox->setEnabled(true);
919 GroupArguments->setEnabled(true);
920 GroupButtons->setEnabled(true);
922 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
924 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925 aViewWindow->SetSelectionMode( CellSelection );
927 SelectionIntoArgument();
930 //=================================================================================
931 // function : enterEvent()
933 //=================================================================================
934 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
936 if (!ConstructorsBox->isEnabled())
937 ActivateThisDialog();
940 //=======================================================================
941 //function : onSelectMesh
943 //=======================================================================
944 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
947 TextLabelElements->setText(tr("SMESH_NAME"));
949 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
950 myFilterBtn->setEnabled(!toSelectMesh);
952 if (myEditCurrentArgument != LineEditElements) {
953 LineEditElements->clear();
957 mySelectionMgr->clearFilters();
958 SMESH::SetPointRepresentation(false);
961 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
962 aViewWindow->SetSelectionMode( ActorSelection );
963 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
964 LineEditElements->setReadOnly(true);
965 LineEditElements->setValidator(0);
967 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
968 aViewWindow->SetSelectionMode( CellSelection );
969 LineEditElements->setReadOnly(false);
970 LineEditElements->setValidator(myIdValidator);
971 onTextChange(LineEditElements->text());
975 SelectionIntoArgument();
978 //=======================================================================
979 //function : onActionClicked
980 //purpose : slot called when an action type changed
981 //=======================================================================
983 void SMESHGUI_TranslationDlg::onActionClicked(int button)
986 for ( int i = 0; i < myMeshes.count(); i++ )
987 aNbGroups += myMeshes[i]->NbGroups();
990 case MOVE_ELEMS_BUTTON:
991 MakeGroupsCheck->setEnabled(false);
992 LineEditNewMesh->setEnabled(false);
994 case COPY_ELEMS_BUTTON:
995 LineEditNewMesh->setEnabled(false);
996 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
997 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
999 case MAKE_MESH_BUTTON:
1000 LineEditNewMesh->setEnabled(true);
1001 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1002 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1006 toDisplaySimulation();
1009 //=======================================================================
1010 //function : setNewMeshName
1011 //purpose : update contents of LineEditNewMesh
1012 //=======================================================================
1014 void SMESHGUI_TranslationDlg::setNewMeshName()
1016 LineEditNewMesh->setText("");
1017 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1019 if ( CheckBoxMesh->isChecked() ) {
1020 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1023 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1024 name = meshSO->GetName().c_str();
1026 if ( !name.isEmpty() )
1027 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1031 //=================================================================================
1032 // function : GetConstructorId()
1034 //=================================================================================
1035 int SMESHGUI_TranslationDlg::GetConstructorId()
1037 return GroupConstructors->checkedId();
1040 //=================================================================================
1041 // function : keyPressEvent()
1043 //=================================================================================
1044 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1046 QDialog::keyPressEvent( e );
1047 if ( e->isAccepted() )
1050 if ( e->key() == Qt::Key_F1 ) {
1056 //=================================================================================
1057 // function : setFilters()
1058 // purpose : SLOT. Called when "Filter" button pressed.
1059 //=================================================================================
1060 void SMESHGUI_TranslationDlg::setFilters()
1062 if(myMeshes.isEmpty()) {
1063 SUIT_MessageBox::critical(this,
1065 tr("NO_MESH_SELECTED"));
1069 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1071 myFilterDlg->SetSelection();
1072 myFilterDlg->SetMesh( myMeshes[0] );
1073 myFilterDlg->SetSourceWg( LineEditElements );
1075 myFilterDlg->show();
1078 //=================================================================================
1079 // function : isValid
1081 //=================================================================================
1082 bool SMESHGUI_TranslationDlg::isValid()
1087 ok = SpinBox1_1->isValid( msg, true ) && ok;
1088 ok = SpinBox1_2->isValid( msg, true ) && ok;
1089 ok = SpinBox1_3->isValid( msg, true ) && ok;
1090 if (GetConstructorId() == 0) {
1091 ok = SpinBox2_1->isValid( msg, true ) && ok;
1092 ok = SpinBox2_2->isValid( msg, true ) && ok;
1093 ok = SpinBox2_3->isValid( msg, true ) && ok;
1097 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1098 if ( !msg.isEmpty() )
1100 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1106 //=================================================================================
1107 // function : onDisplaySimulation
1108 // purpose : Show/Hide preview
1109 //=================================================================================
1110 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1111 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1113 if (isValid() && myNbOkElements) {
1114 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1116 SMESH::long_array_var anElementsId = new SMESH::long_array;
1118 anElementsId->length(aListElementsId.count());
1119 for (int i = 0; i < aListElementsId.count(); i++)
1120 anElementsId[i] = aListElementsId[i].toInt();
1122 SMESH::DirStruct aVector;
1123 if (GetConstructorId() == 0) {
1124 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1125 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1126 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1127 } else if (GetConstructorId() == 1) {
1128 aVector.PS.x = SpinBox1_1->GetValue();
1129 aVector.PS.y = SpinBox1_2->GetValue();
1130 aVector.PS.z = SpinBox1_3->GetValue();
1134 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1135 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1136 SUIT_OverrideCursor aWaitCursor;
1137 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1138 if(CheckBoxMesh->isChecked())
1139 for ( int i = 0; i < myObjects.count(); i++ ) {
1140 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1141 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1142 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1145 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1146 aMeshEditor->Translate(anElementsId, aVector, copy);
1147 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1149 setSimulationPreview( aMeshPreviewStruct );