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 < myObjects.count(); i++ ) {
596 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
597 if ( actor ) SMESH::Update( actor->getIO(), true );
600 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
601 actionButton == MAKE_MESH_BUTTON ) {
602 mySMESHGUI->updateObjBrowser(true); // new groups may appear
603 if( LightApp_Application* anApp =
604 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
605 anApp->browseObjects( anEntryList, isApplyAndClose() );
609 ConstructorsClicked(GetConstructorId());
610 SelectionIntoArgument();
612 SMESHGUI::Modified();
618 //=================================================================================
619 // function : ClickOnOk()
621 //=================================================================================
622 void SMESHGUI_TranslationDlg::ClickOnOk()
624 setIsApplyAndClose( true );
629 //=================================================================================
630 // function : reject()
632 //=================================================================================
633 void SMESHGUI_TranslationDlg::reject()
635 disconnect(mySelectionMgr, 0, this, 0);
636 mySelectionMgr->clearFilters();
637 //mySelectionMgr->clearSelected();
638 if (SMESH::GetCurrentVtkView()) {
639 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
640 SMESH::SetPointRepresentation(false);
642 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
643 aViewWindow->SetSelectionMode( ActorSelection );
644 mySMESHGUI->ResetState();
648 //=================================================================================
649 // function : ClickOnHelp()
651 //=================================================================================
652 void SMESHGUI_TranslationDlg::ClickOnHelp()
654 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
656 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
660 platform = "winapplication";
662 platform = "application";
664 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
665 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
666 arg(app->resourceMgr()->stringValue("ExternalBrowser",
668 arg(myHelpFileName));
672 //=======================================================================
673 // function : onTextChange()
675 //=======================================================================
676 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
678 QLineEdit* send = (QLineEdit*)sender();
681 BusyLocker lock( myBusy );
683 if (send == LineEditElements)
686 buttonOk->setEnabled(false);
687 buttonApply->setEnabled(false);
689 // hilight entered elements
690 SMDS_Mesh* aMesh = 0;
692 aMesh = myActor->GetObject()->GetMesh();
695 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
697 TColStd_MapOfInteger newIndices;
699 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
701 if (send == LineEditElements) {
702 for (int i = 0; i < aListId.count(); i++) {
703 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
705 newIndices.Add(e->GetID());
710 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
711 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
712 aViewWindow->highlight( anIO, true, true );
714 myElementsId = theNewText;
717 if (myNbOkElements) {
718 buttonOk->setEnabled(true);
719 buttonApply->setEnabled(true);
723 //=================================================================================
724 // function : SelectionIntoArgument()
725 // purpose : Called when selection as changed or other case
726 //=================================================================================
727 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
730 BusyLocker lock( myBusy );
733 QString aString = "";
734 onDisplaySimulation(false);
736 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
737 LineEditElements->setText(aString);
739 buttonOk->setEnabled(false);
740 buttonApply->setEnabled(false);
743 if (!GroupButtons->isEnabled()) // inactive
748 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
750 int nbSel = aList.Extent();
755 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
758 myObjectsNames.clear();
761 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
762 Handle(SALOME_InteractiveObject) IO = it.Value();
763 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
764 if ( aMesh->_is_nil() )
767 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
769 anActor = SMESH::FindActorByEntry( IO->getEntry() );
771 if ( !anActor && !CheckBoxMesh->isChecked() )
774 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
775 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
776 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
777 _PTR(GenericAttribute) anAttr;
778 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
779 _PTR(AttributeName) aNameAttr( anAttr );
780 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
781 myObjectsNames << aNameAttr->Value().c_str();
790 // MakeGroups is available if there are groups and "Copy"
792 for ( int i = 0; i < myMeshes.count(); i++ )
793 aNbGroups += myMeshes[i]->NbGroups();
795 if ( aNbGroups == 0 ) {
796 MakeGroupsCheck->setChecked(false);
797 MakeGroupsCheck->setEnabled(false);
799 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
800 MakeGroupsCheck->setEnabled(true);
803 if (CheckBoxMesh->isChecked()) {
804 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
805 if (myMeshes.isEmpty())
808 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
809 myElementsId = aString;
814 myNbOkElements = true;
816 Handle(SALOME_InteractiveObject) IO = aList.First();
817 if ((SMESH::GetMeshByIO(IO))->_is_nil())
820 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
822 anActor = SMESH::FindActorByEntry(IO->getEntry());
823 if (!anActor && !CheckBoxMesh->isChecked())
826 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
830 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
834 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
842 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
843 SpinBox1_1->SetValue(x);
844 SpinBox1_2->SetValue(y);
845 SpinBox1_3->SetValue(z);
846 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
847 SpinBox2_1->SetValue(x);
848 SpinBox2_2->SetValue(y);
849 SpinBox2_3->SetValue(z);
853 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
854 LineEditElements->setText(aString);
855 LineEditElements->repaint();
856 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
857 LineEditElements->setEnabled(true);
862 if (myNbOkElements) {
863 buttonOk->setEnabled(true);
864 buttonApply->setEnabled(true);
866 onDisplaySimulation(true);
869 //=================================================================================
870 // function : SetEditCurrentArgument()
872 //=================================================================================
873 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
875 QPushButton* send = (QPushButton*)sender();
877 disconnect(mySelectionMgr, 0, this, 0);
878 mySelectionMgr->clearSelected();
879 mySelectionMgr->clearFilters();
881 if (send == SelectElementsButton) {
882 myEditCurrentArgument = (QWidget*)LineEditElements;
883 SMESH::SetPointRepresentation(false);
884 if (CheckBoxMesh->isChecked()) {
885 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
886 aViewWindow->SetSelectionMode( ActorSelection );
887 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
890 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
891 aViewWindow->SetSelectionMode( CellSelection );
893 } else if (send == SelectButton1) {
894 myEditCurrentArgument = (QWidget*)SpinBox1_1;
895 SMESH::SetPointRepresentation(true);
897 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
898 aViewWindow->SetSelectionMode( NodeSelection );
899 } else if (send == SelectButton2) {
900 myEditCurrentArgument = (QWidget*)SpinBox2_1;
901 SMESH::SetPointRepresentation(true);
903 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
904 aViewWindow->SetSelectionMode( NodeSelection );
907 myEditCurrentArgument->setFocus();
908 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
909 SelectionIntoArgument();
912 //=================================================================================
913 // function : DeactivateActiveDialog()
915 //=================================================================================
916 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
918 if (ConstructorsBox->isEnabled()) {
919 ConstructorsBox->setEnabled(false);
920 GroupArguments->setEnabled(false);
921 GroupButtons->setEnabled(false);
922 mySMESHGUI->ResetState();
923 mySMESHGUI->SetActiveDialogBox(0);
927 //=================================================================================
928 // function : ActivateThisDialog()
930 //=================================================================================
931 void SMESHGUI_TranslationDlg::ActivateThisDialog()
933 /* Emit a signal to deactivate the active dialog */
934 mySMESHGUI->EmitSignalDeactivateDialog();
935 ConstructorsBox->setEnabled(true);
936 GroupArguments->setEnabled(true);
937 GroupButtons->setEnabled(true);
939 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
941 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
942 aViewWindow->SetSelectionMode( CellSelection );
944 SelectionIntoArgument();
947 //=================================================================================
948 // function : enterEvent()
950 //=================================================================================
951 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
953 if (!ConstructorsBox->isEnabled())
954 ActivateThisDialog();
957 //=======================================================================
958 //function : onSelectMesh
960 //=======================================================================
961 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
964 TextLabelElements->setText(tr("SMESH_NAME"));
966 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
967 myFilterBtn->setEnabled(!toSelectMesh);
969 if (myEditCurrentArgument != LineEditElements) {
970 LineEditElements->clear();
974 mySelectionMgr->clearFilters();
975 SMESH::SetPointRepresentation(false);
978 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
979 aViewWindow->SetSelectionMode( ActorSelection );
980 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
981 LineEditElements->setReadOnly(true);
982 LineEditElements->setValidator(0);
984 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
985 aViewWindow->SetSelectionMode( CellSelection );
986 LineEditElements->setReadOnly(false);
987 LineEditElements->setValidator(myIdValidator);
988 onTextChange(LineEditElements->text());
992 SelectionIntoArgument();
995 //=======================================================================
996 //function : onActionClicked
997 //purpose : slot called when an action type changed
998 //=======================================================================
1000 void SMESHGUI_TranslationDlg::onActionClicked(int button)
1003 for ( int i = 0; i < myMeshes.count(); i++ )
1004 aNbGroups += myMeshes[i]->NbGroups();
1007 case MOVE_ELEMS_BUTTON:
1008 MakeGroupsCheck->setEnabled(false);
1009 LineEditNewMesh->setEnabled(false);
1011 case COPY_ELEMS_BUTTON:
1012 LineEditNewMesh->setEnabled(false);
1013 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1014 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1016 case MAKE_MESH_BUTTON:
1017 LineEditNewMesh->setEnabled(true);
1018 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1019 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1023 toDisplaySimulation();
1026 //=======================================================================
1027 //function : setNewMeshName
1028 //purpose : update contents of LineEditNewMesh
1029 //=======================================================================
1031 void SMESHGUI_TranslationDlg::setNewMeshName()
1033 LineEditNewMesh->setText("");
1034 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1036 if ( CheckBoxMesh->isChecked() ) {
1037 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1040 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1041 name = meshSO->GetName().c_str();
1043 if ( !name.isEmpty() )
1044 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1048 //=================================================================================
1049 // function : GetConstructorId()
1051 //=================================================================================
1052 int SMESHGUI_TranslationDlg::GetConstructorId()
1054 return GroupConstructors->checkedId();
1057 //=================================================================================
1058 // function : keyPressEvent()
1060 //=================================================================================
1061 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1063 QDialog::keyPressEvent( e );
1064 if ( e->isAccepted() )
1067 if ( e->key() == Qt::Key_F1 ) {
1073 //=================================================================================
1074 // function : setFilters()
1075 // purpose : SLOT. Called when "Filter" button pressed.
1076 //=================================================================================
1077 void SMESHGUI_TranslationDlg::setFilters()
1079 if(myMeshes.isEmpty()) {
1080 SUIT_MessageBox::critical(this,
1082 tr("NO_MESH_SELECTED"));
1086 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1088 myFilterDlg->SetSelection();
1089 myFilterDlg->SetMesh( myMeshes[0] );
1090 myFilterDlg->SetSourceWg( LineEditElements );
1092 myFilterDlg->show();
1095 //=================================================================================
1096 // function : isValid
1098 //=================================================================================
1099 bool SMESHGUI_TranslationDlg::isValid()
1104 ok = SpinBox1_1->isValid( msg, true ) && ok;
1105 ok = SpinBox1_2->isValid( msg, true ) && ok;
1106 ok = SpinBox1_3->isValid( msg, true ) && ok;
1107 if (GetConstructorId() == 0) {
1108 ok = SpinBox2_1->isValid( msg, true ) && ok;
1109 ok = SpinBox2_2->isValid( msg, true ) && ok;
1110 ok = SpinBox2_3->isValid( msg, true ) && ok;
1114 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1115 if ( !msg.isEmpty() )
1117 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1123 //=================================================================================
1124 // function : onDisplaySimulation
1125 // purpose : Show/Hide preview
1126 //=================================================================================
1127 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1128 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1130 if (isValid() && myNbOkElements) {
1131 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1133 SMESH::long_array_var anElementsId = new SMESH::long_array;
1135 anElementsId->length(aListElementsId.count());
1136 for (int i = 0; i < aListElementsId.count(); i++)
1137 anElementsId[i] = aListElementsId[i].toInt();
1139 SMESH::DirStruct aVector;
1140 if (GetConstructorId() == 0) {
1141 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1142 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1143 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1144 } else if (GetConstructorId() == 1) {
1145 aVector.PS.x = SpinBox1_1->GetValue();
1146 aVector.PS.y = SpinBox1_2->GetValue();
1147 aVector.PS.z = SpinBox1_3->GetValue();
1151 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1152 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1153 SUIT_OverrideCursor aWaitCursor;
1154 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1155 if(CheckBoxMesh->isChecked())
1156 for ( int i = 0; i < myObjects.count(); i++ ) {
1157 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1158 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1159 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1162 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1163 aMeshEditor->Translate(anElementsId, aVector, copy);
1164 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1166 setSimulationPreview( aMeshPreviewStruct );