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
106 //To disable automatic genericobj management, the following line should be commented.
107 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
108 #define WITHGENERICOBJ
110 //=================================================================================
111 // class : SMESHGUI_TranslationDlg()
113 //=================================================================================
114 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
115 SMESHGUI_MultiPreviewDlg( theModule ),
116 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
119 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
120 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
121 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
124 setAttribute(Qt::WA_DeleteOnClose, true);
125 setWindowTitle(tr("SMESH_TRANSLATION"));
126 setSizeGripEnabled(true);
128 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
129 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
130 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
132 /***************************************************************/
133 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
134 GroupConstructors = new QButtonGroup(this);
135 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
136 ConstructorsBoxLayout->setSpacing(SPACING);
137 ConstructorsBoxLayout->setMargin(MARGIN);
139 RadioButton1= new QRadioButton(ConstructorsBox);
140 RadioButton1->setIcon(image0);
141 RadioButton2= new QRadioButton(ConstructorsBox);
142 RadioButton2->setIcon(image1);
144 ConstructorsBoxLayout->addWidget(RadioButton1);
145 ConstructorsBoxLayout->addWidget(RadioButton2);
146 GroupConstructors->addButton(RadioButton1, 0);
147 GroupConstructors->addButton(RadioButton2, 1);
149 /***************************************************************/
150 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
151 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
152 GroupArgumentsLayout->setSpacing(SPACING);
153 GroupArgumentsLayout->setMargin(MARGIN);
155 myIdValidator = new SMESHGUI_IdValidator(this);
157 // Controls for elements selection
158 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
159 SelectElementsButton = new QPushButton(GroupArguments);
160 SelectElementsButton->setIcon(image2);
161 LineEditElements = new QLineEdit(GroupArguments);
162 LineEditElements->setValidator(myIdValidator);
163 LineEditElements->setMaxLength(-1);
164 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
165 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
167 // Control for the whole mesh selection
168 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
170 // Controls for vector and points selection
171 TextLabel1 = new QLabel(GroupArguments);
172 SelectButton1 = new QPushButton(GroupArguments);
173 SelectButton1->setIcon(image2);
175 TextLabel1_1 = new QLabel(GroupArguments);
176 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel1_2 = new QLabel(GroupArguments);
178 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel1_3 = new QLabel(GroupArguments);
180 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
183 SelectButton2 = new QPushButton(GroupArguments);
184 SelectButton2->setIcon(image2);
186 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
187 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
188 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
189 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
190 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
191 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
193 // switch of action type
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->addSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 MakeGroupsCheck->setChecked(false);
215 // Name of a mesh to create
216 LineEditNewMesh = new QLineEdit(GroupArguments);
219 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
222 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
223 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
224 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
225 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
226 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
227 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
228 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
229 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
230 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
231 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
232 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
233 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
234 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
235 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
236 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
237 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
238 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
239 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
240 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
241 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
242 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
243 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
244 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
245 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
246 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
248 /***************************************************************/
249 GroupButtons = new QGroupBox(this);
250 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
251 GroupButtonsLayout->setSpacing(SPACING);
252 GroupButtonsLayout->setMargin(MARGIN);
254 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
255 buttonOk->setAutoDefault(true);
256 buttonOk->setDefault(true);
257 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
258 buttonApply->setAutoDefault(true);
259 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
260 buttonCancel->setAutoDefault(true);
261 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
262 buttonHelp->setAutoDefault(true);
264 GroupButtonsLayout->addWidget(buttonOk);
265 GroupButtonsLayout->addSpacing(10);
266 GroupButtonsLayout->addWidget(buttonApply);
267 GroupButtonsLayout->addSpacing(10);
268 GroupButtonsLayout->addStretch();
269 GroupButtonsLayout->addWidget(buttonCancel);
270 GroupButtonsLayout->addWidget(buttonHelp);
272 /***************************************************************/
273 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
274 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
275 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
277 /* Initialisations */
278 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
280 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
282 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
283 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
285 RadioButton1->setChecked(true);
287 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
289 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
291 // Costruction of the logical filter
292 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
293 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
295 QList<SUIT_SelectionFilter*> aListOfFilters;
296 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
297 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
299 myMeshOrSubMeshOrGroupFilter =
300 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
302 myHelpFileName = "translation_page.html";
306 /* signals and slots connections */
307 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
308 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
309 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
310 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
311 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
313 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
314 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
315 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
317 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
318 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
319 /* to close dialog if study change */
320 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
321 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
322 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
323 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
325 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox2_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox2_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
331 connect(SpinBox2_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
334 //To Connect preview check box
335 connectPreviewControl();
337 ConstructorsClicked(0);
338 SelectionIntoArgument();
339 onActionClicked(MOVE_ELEMS_BUTTON);
342 //=================================================================================
343 // function : ~SMESHGUI_TranslationDlg()
344 // purpose : Destroys the object and frees any allocated resources
345 //=================================================================================
346 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
349 myFilterDlg->setParent( 0 );
355 //=================================================================================
358 //=================================================================================
359 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
363 myObjectsNames.clear();
366 myEditCurrentArgument = 0;
367 LineEditElements->clear();
371 buttonOk->setEnabled(false);
372 buttonApply->setEnabled(false);
377 SpinBox1_1->SetValue(0.0);
378 SpinBox1_2->SetValue(0.0);
379 SpinBox1_3->SetValue(0.0);
380 SpinBox2_1->SetValue(0.0);
381 SpinBox2_2->SetValue(0.0);
382 SpinBox2_3->SetValue(0.0);
384 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
385 CheckBoxMesh->setChecked(false);
386 // MakeGroupsCheck->setChecked(false);
387 // MakeGroupsCheck->setEnabled(false);
388 myPreviewCheckBox->setChecked(false);
389 onDisplaySimulation(false);
394 //=================================================================================
395 // function : ConstructorsClicked()
396 // purpose : Radio button management
397 //=================================================================================
398 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
400 disconnect(mySelectionMgr, 0, this, 0);
402 switch (constructorId) {
405 TextLabel1->setText(tr("SMESH_POINT_1"));
406 TextLabel1_1->setText(tr("SMESH_X"));
407 TextLabel1_2->setText(tr("SMESH_Y"));
408 TextLabel1_3->setText(tr("SMESH_Z"));
410 SelectButton1->show();
412 SelectButton2->show();
413 TextLabel2_1->show();
415 TextLabel2_2->show();
417 TextLabel2_3->show();
423 TextLabel1->setText(tr("SMESH_VECTOR"));
424 TextLabel1_1->setText(tr("SMESH_DX"));
425 TextLabel1_2->setText(tr("SMESH_DY"));
426 TextLabel1_3->setText(tr("SMESH_DZ"));
428 SelectButton1->hide();
430 SelectButton2->hide();
431 TextLabel2_1->hide();
433 TextLabel2_2->hide();
435 TextLabel2_3->hide();
441 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
442 SMESH::SetPointRepresentation(false);
443 if (!CheckBoxMesh->isChecked())
444 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
445 aViewWindow->SetSelectionMode( CellSelection );
448 myEditCurrentArgument = (QWidget*)LineEditElements;
449 LineEditElements->setFocus();
451 if (CheckBoxMesh->isChecked())
454 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
456 onDisplaySimulation(true);
458 QApplication::instance()->processEvents();
463 //=================================================================================
464 // function : ClickOnApply()
466 //=================================================================================
467 bool SMESHGUI_TranslationDlg::ClickOnApply()
469 if (mySMESHGUI->isActiveStudyLocked())
475 if (myNbOkElements) {
476 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
478 SMESH::long_array_var anElementsId = new SMESH::long_array;
480 anElementsId->length(aListElementsId.count());
481 for (int i = 0; i < aListElementsId.count(); i++)
482 anElementsId[i] = aListElementsId[i].toInt();
484 SMESH::DirStruct aVector;
485 QStringList aParameters;
486 if (GetConstructorId() == 0) {
487 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
488 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
489 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
490 // not supported so far
491 // aParameters << QString("%1 - %2").arg( SpinBox2_1->text() ).arg( SpinBox1_1->text() );
492 // aParameters << QString("%1 - %2").arg( SpinBox2_2->text() ).arg( SpinBox1_2->text() );
493 // aParameters << QString("%1 - %2").arg( SpinBox2_3->text() ).arg( SpinBox1_3->text() );
494 } else if (GetConstructorId() == 1) {
495 aVector.PS.x = SpinBox1_1->GetValue();
496 aVector.PS.y = SpinBox1_2->GetValue();
497 aVector.PS.z = SpinBox1_3->GetValue();
498 aParameters << SpinBox1_1->text();
499 aParameters << SpinBox1_2->text();
500 aParameters << SpinBox1_3->text();
503 int actionButton = ActionGroup->checkedId();
504 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
505 QStringList anEntryList;
507 SUIT_OverrideCursor aWaitCursor;
509 switch ( actionButton ) {
510 case MOVE_ELEMS_BUTTON:
511 if(CheckBoxMesh->isChecked())
512 for ( int i = 0; i < myObjects.count(); i++ ) {
513 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
514 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
515 aMeshEditor->TranslateObject(myObjects[i], aVector, false);
518 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
519 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
520 aMeshEditor->Translate(anElementsId, aVector, false);
523 case COPY_ELEMS_BUTTON:
525 SMESH::ListOfGroups_var groups;
526 if(CheckBoxMesh->isChecked()) {
527 for ( int i = 0; i < myObjects.count(); i++ ) {
528 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
529 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
530 groups = aMeshEditor->TranslateObjectMakeGroups(myObjects[i],aVector);
534 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
535 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
536 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
540 if(CheckBoxMesh->isChecked()) {
541 for ( int i = 0; i < myObjects.count(); i++ ) {
542 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
543 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
544 aMeshEditor->TranslateObject(myObjects[i], aVector, true);
548 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
549 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
550 aMeshEditor->Translate(anElementsId, aVector, true);
554 case MAKE_MESH_BUTTON: {
555 SMESH::SMESH_Mesh_var mesh;
556 if (CheckBoxMesh->isChecked()) {
557 for ( int i = 0; i < myObjects.count(); i++ ) {
558 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
559 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
560 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
561 mesh = aMeshEditor->TranslateObjectMakeMesh(myObjects[i], aVector, makeGroups,
562 aName.toLatin1().data());
563 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
564 anEntryList.append( aSObject->GetID().c_str() );
566 #ifdef WITHGENERICOBJ
567 // obj has been published in study. Its refcount has been incremented.
568 // It is safe to decrement its refcount
569 // so that it will be destroyed when the entry in study will be removed
575 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
576 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
577 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
578 LineEditNewMesh->text().toLatin1().data());
579 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
580 anEntryList.append( aSObject->GetID().c_str() );
582 #ifdef WITHGENERICOBJ
583 // obj has been published in study. Its refcount has been incremented.
584 // It is safe to decrement its refcount
585 // so that it will be destroyed when the entry in study will be removed
595 for ( int i = 0; i < myMeshes.count(); i++ )
596 SMESH::Update( (SMESH::FindActorByObject( myMeshes[i] ))->getIO(), true );
598 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
599 actionButton == MAKE_MESH_BUTTON ) {
600 mySMESHGUI->updateObjBrowser(true); // new groups may appear
601 if( LightApp_Application* anApp =
602 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
603 anApp->browseObjects( anEntryList, isApplyAndClose() );
607 ConstructorsClicked(GetConstructorId());
608 SelectionIntoArgument();
610 SMESHGUI::Modified();
616 //=================================================================================
617 // function : ClickOnOk()
619 //=================================================================================
620 void SMESHGUI_TranslationDlg::ClickOnOk()
622 setIsApplyAndClose( true );
627 //=================================================================================
628 // function : reject()
630 //=================================================================================
631 void SMESHGUI_TranslationDlg::reject()
633 disconnect(mySelectionMgr, 0, this, 0);
634 mySelectionMgr->clearFilters();
635 //mySelectionMgr->clearSelected();
636 if (SMESH::GetCurrentVtkView()) {
637 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
638 SMESH::SetPointRepresentation(false);
640 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
641 aViewWindow->SetSelectionMode( ActorSelection );
642 mySMESHGUI->ResetState();
646 //=================================================================================
647 // function : ClickOnHelp()
649 //=================================================================================
650 void SMESHGUI_TranslationDlg::ClickOnHelp()
652 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
654 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
658 platform = "winapplication";
660 platform = "application";
662 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
663 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
664 arg(app->resourceMgr()->stringValue("ExternalBrowser",
666 arg(myHelpFileName));
670 //=======================================================================
671 // function : onTextChange()
673 //=======================================================================
674 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
676 QLineEdit* send = (QLineEdit*)sender();
679 BusyLocker lock( myBusy );
681 if (send == LineEditElements)
684 buttonOk->setEnabled(false);
685 buttonApply->setEnabled(false);
687 // hilight entered elements
688 SMDS_Mesh* aMesh = 0;
690 aMesh = myActor->GetObject()->GetMesh();
693 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
695 TColStd_MapOfInteger newIndices;
697 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
699 if (send == LineEditElements) {
700 for (int i = 0; i < aListId.count(); i++) {
701 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
703 newIndices.Add(e->GetID());
708 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
709 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
710 aViewWindow->highlight( anIO, true, true );
712 myElementsId = theNewText;
715 if (myNbOkElements) {
716 buttonOk->setEnabled(true);
717 buttonApply->setEnabled(true);
721 //=================================================================================
722 // function : SelectionIntoArgument()
723 // purpose : Called when selection as changed or other case
724 //=================================================================================
725 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
728 BusyLocker lock( myBusy );
731 QString aString = "";
732 onDisplaySimulation(false);
734 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
735 LineEditElements->setText(aString);
737 buttonOk->setEnabled(false);
738 buttonApply->setEnabled(false);
741 if (!GroupButtons->isEnabled()) // inactive
746 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
748 int nbSel = aList.Extent();
753 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
756 myObjectsNames.clear();
759 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
760 Handle(SALOME_InteractiveObject) IO = it.Value();
761 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
762 if ( aMesh->_is_nil() )
765 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
767 anActor = SMESH::FindActorByEntry( IO->getEntry() );
769 if ( !anActor && !CheckBoxMesh->isChecked() )
772 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
773 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
774 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
775 _PTR(GenericAttribute) anAttr;
776 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
777 _PTR(AttributeName) aNameAttr( anAttr );
778 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
779 myObjectsNames << aNameAttr->Value().c_str();
788 // MakeGroups is available if there are groups and "Copy"
790 for ( int i = 0; i < myMeshes.count(); i++ )
791 aNbGroups += myMeshes[i]->NbGroups();
793 if ( aNbGroups == 0 ) {
794 MakeGroupsCheck->setChecked(false);
795 MakeGroupsCheck->setEnabled(false);
797 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
798 MakeGroupsCheck->setEnabled(true);
801 if (CheckBoxMesh->isChecked()) {
802 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
803 if (myMeshes.isEmpty())
806 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
807 myElementsId = aString;
812 myNbOkElements = true;
814 Handle(SALOME_InteractiveObject) IO = aList.First();
815 if ((SMESH::GetMeshByIO(IO))->_is_nil())
818 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
820 anActor = SMESH::FindActorByEntry(IO->getEntry());
821 if (!anActor && !CheckBoxMesh->isChecked())
824 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
828 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
832 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
840 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
841 SpinBox1_1->SetValue(x);
842 SpinBox1_2->SetValue(y);
843 SpinBox1_3->SetValue(z);
844 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
845 SpinBox2_1->SetValue(x);
846 SpinBox2_2->SetValue(y);
847 SpinBox2_3->SetValue(z);
851 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
852 LineEditElements->setText(aString);
853 LineEditElements->repaint();
854 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
855 LineEditElements->setEnabled(true);
860 if (myNbOkElements) {
861 buttonOk->setEnabled(true);
862 buttonApply->setEnabled(true);
864 onDisplaySimulation(true);
867 //=================================================================================
868 // function : SetEditCurrentArgument()
870 //=================================================================================
871 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
873 QPushButton* send = (QPushButton*)sender();
875 disconnect(mySelectionMgr, 0, this, 0);
876 mySelectionMgr->clearSelected();
877 mySelectionMgr->clearFilters();
879 if (send == SelectElementsButton) {
880 myEditCurrentArgument = (QWidget*)LineEditElements;
881 SMESH::SetPointRepresentation(false);
882 if (CheckBoxMesh->isChecked()) {
883 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
884 aViewWindow->SetSelectionMode( ActorSelection );
885 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
888 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
889 aViewWindow->SetSelectionMode( CellSelection );
891 } else if (send == SelectButton1) {
892 myEditCurrentArgument = (QWidget*)SpinBox1_1;
893 SMESH::SetPointRepresentation(true);
895 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
896 aViewWindow->SetSelectionMode( NodeSelection );
897 } else if (send == SelectButton2) {
898 myEditCurrentArgument = (QWidget*)SpinBox2_1;
899 SMESH::SetPointRepresentation(true);
901 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
902 aViewWindow->SetSelectionMode( NodeSelection );
905 myEditCurrentArgument->setFocus();
906 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
907 SelectionIntoArgument();
910 //=================================================================================
911 // function : DeactivateActiveDialog()
913 //=================================================================================
914 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
916 if (ConstructorsBox->isEnabled()) {
917 ConstructorsBox->setEnabled(false);
918 GroupArguments->setEnabled(false);
919 GroupButtons->setEnabled(false);
920 mySMESHGUI->ResetState();
921 mySMESHGUI->SetActiveDialogBox(0);
925 //=================================================================================
926 // function : ActivateThisDialog()
928 //=================================================================================
929 void SMESHGUI_TranslationDlg::ActivateThisDialog()
931 /* Emit a signal to deactivate the active dialog */
932 mySMESHGUI->EmitSignalDeactivateDialog();
933 ConstructorsBox->setEnabled(true);
934 GroupArguments->setEnabled(true);
935 GroupButtons->setEnabled(true);
937 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
939 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
940 aViewWindow->SetSelectionMode( CellSelection );
942 SelectionIntoArgument();
945 //=================================================================================
946 // function : enterEvent()
948 //=================================================================================
949 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
951 if (!ConstructorsBox->isEnabled())
952 ActivateThisDialog();
955 //=======================================================================
956 //function : onSelectMesh
958 //=======================================================================
959 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
962 TextLabelElements->setText(tr("SMESH_NAME"));
964 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
965 myFilterBtn->setEnabled(!toSelectMesh);
967 if (myEditCurrentArgument != LineEditElements) {
968 LineEditElements->clear();
972 mySelectionMgr->clearFilters();
973 SMESH::SetPointRepresentation(false);
976 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
977 aViewWindow->SetSelectionMode( ActorSelection );
978 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
979 LineEditElements->setReadOnly(true);
980 LineEditElements->setValidator(0);
982 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
983 aViewWindow->SetSelectionMode( CellSelection );
984 LineEditElements->setReadOnly(false);
985 LineEditElements->setValidator(myIdValidator);
986 onTextChange(LineEditElements->text());
990 SelectionIntoArgument();
993 //=======================================================================
994 //function : onActionClicked
995 //purpose : slot called when an action type changed
996 //=======================================================================
998 void SMESHGUI_TranslationDlg::onActionClicked(int button)
1001 for ( int i = 0; i < myMeshes.count(); i++ )
1002 aNbGroups += myMeshes[i]->NbGroups();
1005 case MOVE_ELEMS_BUTTON:
1006 MakeGroupsCheck->setEnabled(false);
1007 LineEditNewMesh->setEnabled(false);
1009 case COPY_ELEMS_BUTTON:
1010 LineEditNewMesh->setEnabled(false);
1011 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1012 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1014 case MAKE_MESH_BUTTON:
1015 LineEditNewMesh->setEnabled(true);
1016 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1017 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1021 toDisplaySimulation();
1024 //=======================================================================
1025 //function : setNewMeshName
1026 //purpose : update contents of LineEditNewMesh
1027 //=======================================================================
1029 void SMESHGUI_TranslationDlg::setNewMeshName()
1031 LineEditNewMesh->setText("");
1032 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1034 if ( CheckBoxMesh->isChecked() ) {
1035 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1038 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1039 name = meshSO->GetName().c_str();
1041 if ( !name.isEmpty() )
1042 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1046 //=================================================================================
1047 // function : GetConstructorId()
1049 //=================================================================================
1050 int SMESHGUI_TranslationDlg::GetConstructorId()
1052 return GroupConstructors->checkedId();
1055 //=================================================================================
1056 // function : keyPressEvent()
1058 //=================================================================================
1059 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1061 QDialog::keyPressEvent( e );
1062 if ( e->isAccepted() )
1065 if ( e->key() == Qt::Key_F1 ) {
1071 //=================================================================================
1072 // function : setFilters()
1073 // purpose : SLOT. Called when "Filter" button pressed.
1074 //=================================================================================
1075 void SMESHGUI_TranslationDlg::setFilters()
1077 if(myMeshes.isEmpty()) {
1078 SUIT_MessageBox::critical(this,
1080 tr("NO_MESH_SELECTED"));
1084 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1086 myFilterDlg->SetSelection();
1087 myFilterDlg->SetMesh( myMeshes[0] );
1088 myFilterDlg->SetSourceWg( LineEditElements );
1090 myFilterDlg->show();
1093 //=================================================================================
1094 // function : isValid
1096 //=================================================================================
1097 bool SMESHGUI_TranslationDlg::isValid()
1102 ok = SpinBox1_1->isValid( msg, true ) && ok;
1103 ok = SpinBox1_2->isValid( msg, true ) && ok;
1104 ok = SpinBox1_3->isValid( msg, true ) && ok;
1105 if (GetConstructorId() == 0) {
1106 ok = SpinBox2_1->isValid( msg, true ) && ok;
1107 ok = SpinBox2_2->isValid( msg, true ) && ok;
1108 ok = SpinBox2_3->isValid( msg, true ) && ok;
1112 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1113 if ( !msg.isEmpty() )
1115 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1121 //=================================================================================
1122 // function : onDisplaySimulation
1123 // purpose : Show/Hide preview
1124 //=================================================================================
1125 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1126 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1128 if (isValid() && myNbOkElements) {
1129 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1131 SMESH::long_array_var anElementsId = new SMESH::long_array;
1133 anElementsId->length(aListElementsId.count());
1134 for (int i = 0; i < aListElementsId.count(); i++)
1135 anElementsId[i] = aListElementsId[i].toInt();
1137 SMESH::DirStruct aVector;
1138 if (GetConstructorId() == 0) {
1139 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1140 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1141 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1142 } else if (GetConstructorId() == 1) {
1143 aVector.PS.x = SpinBox1_1->GetValue();
1144 aVector.PS.y = SpinBox1_2->GetValue();
1145 aVector.PS.z = SpinBox1_3->GetValue();
1149 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1150 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1151 SUIT_OverrideCursor aWaitCursor;
1152 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1153 if(CheckBoxMesh->isChecked())
1154 for ( int i = 0; i < myObjects.count(); i++ ) {
1155 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1156 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1157 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1160 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1161 aMeshEditor->Translate(anElementsId, aVector, copy);
1162 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1164 setSimulationPreview( aMeshPreviewStruct );