1 // Copyright (C) 2007-2013 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 // 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);
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() );
563 // obj has been published in study. Its refcount has been incremented.
564 // It is safe to decrement its refcount
565 // so that it will be destroyed when the entry in study will be removed
570 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
571 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
572 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
573 LineEditNewMesh->text().toLatin1().data());
574 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
575 anEntryList.append( aSObject->GetID().c_str() );
577 // obj has been published in study. Its refcount has been incremented.
578 // It is safe to decrement its refcount
579 // so that it will be destroyed when the entry in study will be removed
588 for ( int i = 0; i < myObjects.count(); i++ ) {
589 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
590 if ( actor ) SMESH::Update( actor->getIO(), true );
593 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
594 actionButton == MAKE_MESH_BUTTON ) {
595 mySMESHGUI->updateObjBrowser(true); // new groups may appear
596 if( LightApp_Application* anApp =
597 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
598 anApp->browseObjects( anEntryList, isApplyAndClose() );
602 ConstructorsClicked(GetConstructorId());
603 SelectionIntoArgument();
605 SMESHGUI::Modified();
611 //=================================================================================
612 // function : ClickOnOk()
614 //=================================================================================
615 void SMESHGUI_TranslationDlg::ClickOnOk()
617 setIsApplyAndClose( true );
622 //=================================================================================
623 // function : reject()
625 //=================================================================================
626 void SMESHGUI_TranslationDlg::reject()
628 disconnect(mySelectionMgr, 0, this, 0);
629 mySelectionMgr->clearFilters();
630 //mySelectionMgr->clearSelected();
631 if (SMESH::GetCurrentVtkView()) {
632 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
633 SMESH::SetPointRepresentation(false);
635 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
636 aViewWindow->SetSelectionMode( ActorSelection );
637 mySMESHGUI->ResetState();
641 //=================================================================================
642 // function : ClickOnHelp()
644 //=================================================================================
645 void SMESHGUI_TranslationDlg::ClickOnHelp()
647 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
649 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
653 platform = "winapplication";
655 platform = "application";
657 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
658 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
659 arg(app->resourceMgr()->stringValue("ExternalBrowser",
661 arg(myHelpFileName));
665 //=======================================================================
666 // function : onTextChange()
668 //=======================================================================
669 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
671 QLineEdit* send = (QLineEdit*)sender();
674 BusyLocker lock( myBusy );
676 if (send == LineEditElements)
679 buttonOk->setEnabled(false);
680 buttonApply->setEnabled(false);
682 // hilight entered elements
683 SMDS_Mesh* aMesh = 0;
685 aMesh = myActor->GetObject()->GetMesh();
688 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
690 TColStd_MapOfInteger newIndices;
692 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
694 if (send == LineEditElements) {
695 for (int i = 0; i < aListId.count(); i++) {
696 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
698 newIndices.Add(e->GetID());
703 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
704 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
705 aViewWindow->highlight( anIO, true, true );
707 myElementsId = theNewText;
710 if (myNbOkElements) {
711 buttonOk->setEnabled(true);
712 buttonApply->setEnabled(true);
716 //=================================================================================
717 // function : SelectionIntoArgument()
718 // purpose : Called when selection as changed or other case
719 //=================================================================================
720 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
723 BusyLocker lock( myBusy );
726 QString aString = "";
727 onDisplaySimulation(false);
729 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
730 LineEditElements->setText(aString);
732 buttonOk->setEnabled(false);
733 buttonApply->setEnabled(false);
736 if (!GroupButtons->isEnabled()) // inactive
741 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
743 int nbSel = aList.Extent();
748 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
751 myObjectsNames.clear();
754 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
755 Handle(SALOME_InteractiveObject) IO = it.Value();
756 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
757 if ( aMesh->_is_nil() )
760 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
762 anActor = SMESH::FindActorByEntry( IO->getEntry() );
764 if ( !anActor && !CheckBoxMesh->isChecked() )
767 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
768 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
769 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
770 _PTR(GenericAttribute) anAttr;
771 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
772 _PTR(AttributeName) aNameAttr( anAttr );
773 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
774 myObjectsNames << aNameAttr->Value().c_str();
783 // MakeGroups is available if there are groups and "Copy"
785 for ( int i = 0; i < myMeshes.count(); i++ )
786 aNbGroups += myMeshes[i]->NbGroups();
788 if ( aNbGroups == 0 ) {
789 MakeGroupsCheck->setChecked(false);
790 MakeGroupsCheck->setEnabled(false);
792 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
793 MakeGroupsCheck->setEnabled(true);
796 if (CheckBoxMesh->isChecked()) {
797 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
798 if (myMeshes.isEmpty())
801 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
802 myElementsId = aString;
807 myNbOkElements = true;
809 Handle(SALOME_InteractiveObject) IO = aList.First();
810 if ((SMESH::GetMeshByIO(IO))->_is_nil())
813 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
815 anActor = SMESH::FindActorByEntry(IO->getEntry());
816 if (!anActor && !CheckBoxMesh->isChecked())
819 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
823 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
827 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
835 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
836 SpinBox1_1->SetValue(x);
837 SpinBox1_2->SetValue(y);
838 SpinBox1_3->SetValue(z);
839 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
840 SpinBox2_1->SetValue(x);
841 SpinBox2_2->SetValue(y);
842 SpinBox2_3->SetValue(z);
846 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
847 LineEditElements->setText(aString);
848 LineEditElements->repaint();
849 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
850 LineEditElements->setEnabled(true);
855 if (myNbOkElements) {
856 buttonOk->setEnabled(true);
857 buttonApply->setEnabled(true);
859 onDisplaySimulation(true);
862 //=================================================================================
863 // function : SetEditCurrentArgument()
865 //=================================================================================
866 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
868 QPushButton* send = (QPushButton*)sender();
870 disconnect(mySelectionMgr, 0, this, 0);
871 mySelectionMgr->clearSelected();
872 mySelectionMgr->clearFilters();
874 if (send == SelectElementsButton) {
875 myEditCurrentArgument = (QWidget*)LineEditElements;
876 SMESH::SetPointRepresentation(false);
877 if (CheckBoxMesh->isChecked()) {
878 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
879 aViewWindow->SetSelectionMode( ActorSelection );
880 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
883 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
884 aViewWindow->SetSelectionMode( CellSelection );
886 } else if (send == SelectButton1) {
887 myEditCurrentArgument = (QWidget*)SpinBox1_1;
888 SMESH::SetPointRepresentation(true);
890 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891 aViewWindow->SetSelectionMode( NodeSelection );
892 } else if (send == SelectButton2) {
893 myEditCurrentArgument = (QWidget*)SpinBox2_1;
894 SMESH::SetPointRepresentation(true);
896 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
897 aViewWindow->SetSelectionMode( NodeSelection );
900 myEditCurrentArgument->setFocus();
901 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
902 SelectionIntoArgument();
905 //=================================================================================
906 // function : DeactivateActiveDialog()
908 //=================================================================================
909 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
911 if (ConstructorsBox->isEnabled()) {
912 ConstructorsBox->setEnabled(false);
913 GroupArguments->setEnabled(false);
914 GroupButtons->setEnabled(false);
915 mySMESHGUI->ResetState();
916 mySMESHGUI->SetActiveDialogBox(0);
920 //=================================================================================
921 // function : ActivateThisDialog()
923 //=================================================================================
924 void SMESHGUI_TranslationDlg::ActivateThisDialog()
926 /* Emit a signal to deactivate the active dialog */
927 mySMESHGUI->EmitSignalDeactivateDialog();
928 ConstructorsBox->setEnabled(true);
929 GroupArguments->setEnabled(true);
930 GroupButtons->setEnabled(true);
932 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
934 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935 aViewWindow->SetSelectionMode( CellSelection );
937 SelectionIntoArgument();
940 //=================================================================================
941 // function : enterEvent()
943 //=================================================================================
944 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
946 if (!ConstructorsBox->isEnabled())
947 ActivateThisDialog();
950 //=======================================================================
951 //function : onSelectMesh
953 //=======================================================================
954 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
957 TextLabelElements->setText(tr("SMESH_NAME"));
959 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
960 myFilterBtn->setEnabled(!toSelectMesh);
962 if (myEditCurrentArgument != LineEditElements) {
963 LineEditElements->clear();
967 mySelectionMgr->clearFilters();
968 SMESH::SetPointRepresentation(false);
971 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
972 aViewWindow->SetSelectionMode( ActorSelection );
973 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
974 LineEditElements->setReadOnly(true);
975 LineEditElements->setValidator(0);
977 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
978 aViewWindow->SetSelectionMode( CellSelection );
979 LineEditElements->setReadOnly(false);
980 LineEditElements->setValidator(myIdValidator);
981 onTextChange(LineEditElements->text());
985 SelectionIntoArgument();
988 //=======================================================================
989 //function : onActionClicked
990 //purpose : slot called when an action type changed
991 //=======================================================================
993 void SMESHGUI_TranslationDlg::onActionClicked(int button)
996 for ( int i = 0; i < myMeshes.count(); i++ )
997 aNbGroups += myMeshes[i]->NbGroups();
1000 case MOVE_ELEMS_BUTTON:
1001 MakeGroupsCheck->setEnabled(false);
1002 LineEditNewMesh->setEnabled(false);
1004 case COPY_ELEMS_BUTTON:
1005 LineEditNewMesh->setEnabled(false);
1006 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1007 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1009 case MAKE_MESH_BUTTON:
1010 LineEditNewMesh->setEnabled(true);
1011 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1012 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1016 toDisplaySimulation();
1019 //=======================================================================
1020 //function : setNewMeshName
1021 //purpose : update contents of LineEditNewMesh
1022 //=======================================================================
1024 void SMESHGUI_TranslationDlg::setNewMeshName()
1026 LineEditNewMesh->setText("");
1027 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1029 if ( CheckBoxMesh->isChecked() ) {
1030 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1033 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1034 name = meshSO->GetName().c_str();
1036 if ( !name.isEmpty() )
1037 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1041 //=================================================================================
1042 // function : GetConstructorId()
1044 //=================================================================================
1045 int SMESHGUI_TranslationDlg::GetConstructorId()
1047 return GroupConstructors->checkedId();
1050 //=================================================================================
1051 // function : keyPressEvent()
1053 //=================================================================================
1054 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1056 QDialog::keyPressEvent( e );
1057 if ( e->isAccepted() )
1060 if ( e->key() == Qt::Key_F1 ) {
1066 //=================================================================================
1067 // function : setFilters()
1068 // purpose : SLOT. Called when "Filter" button pressed.
1069 //=================================================================================
1070 void SMESHGUI_TranslationDlg::setFilters()
1072 if(myMeshes.isEmpty()) {
1073 SUIT_MessageBox::critical(this,
1075 tr("NO_MESH_SELECTED"));
1079 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1081 myFilterDlg->SetSelection();
1082 myFilterDlg->SetMesh( myMeshes[0] );
1083 myFilterDlg->SetSourceWg( LineEditElements );
1085 myFilterDlg->show();
1088 //=================================================================================
1089 // function : isValid
1091 //=================================================================================
1092 bool SMESHGUI_TranslationDlg::isValid()
1097 ok = SpinBox1_1->isValid( msg, true ) && ok;
1098 ok = SpinBox1_2->isValid( msg, true ) && ok;
1099 ok = SpinBox1_3->isValid( msg, true ) && ok;
1100 if (GetConstructorId() == 0) {
1101 ok = SpinBox2_1->isValid( msg, true ) && ok;
1102 ok = SpinBox2_2->isValid( msg, true ) && ok;
1103 ok = SpinBox2_3->isValid( msg, true ) && ok;
1107 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1108 if ( !msg.isEmpty() )
1110 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1116 //=================================================================================
1117 // function : onDisplaySimulation
1118 // purpose : Show/Hide preview
1119 //=================================================================================
1120 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1121 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1123 if (isValid() && myNbOkElements) {
1124 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1126 SMESH::long_array_var anElementsId = new SMESH::long_array;
1128 anElementsId->length(aListElementsId.count());
1129 for (int i = 0; i < aListElementsId.count(); i++)
1130 anElementsId[i] = aListElementsId[i].toInt();
1132 SMESH::DirStruct aVector;
1133 if (GetConstructorId() == 0) {
1134 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1135 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1136 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1137 } else if (GetConstructorId() == 1) {
1138 aVector.PS.x = SpinBox1_1->GetValue();
1139 aVector.PS.y = SpinBox1_2->GetValue();
1140 aVector.PS.z = SpinBox1_3->GetValue();
1144 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1145 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1146 SUIT_OverrideCursor aWaitCursor;
1147 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1148 if(CheckBoxMesh->isChecked())
1149 for ( int i = 0; i < myObjects.count(); i++ ) {
1150 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1151 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1152 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1155 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1156 aMeshEditor->Translate(anElementsId, aVector, copy);
1157 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1159 setSimulationPreview( aMeshPreviewStruct );