1 // Copyright (C) 2007-2010 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_TranslationDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_TranslationDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_MeshEditPreview.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 \brief Simple 'busy state' flag locker.
94 //! Constructor. Sets passed boolean flag to \c true.
95 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
96 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
97 ~BusyLocker() { myBusy = false; }
99 bool& myBusy; //! External 'busy state' boolean flag
105 //To disable automatic genericobj management, the following line should be commented.
106 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
107 #define WITHGENERICOBJ
109 //=================================================================================
110 // class : SMESHGUI_TranslationDlg()
112 //=================================================================================
113 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
114 SMESHGUI_PreviewDlg( theModule ),
115 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
117 mySelectedObject(SMESH::SMESH_IDSource::_nil())
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 (MESHorSUBMESH);
293 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (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(ClickOnCancel()));
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(ClickOnCancel()));
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()));
332 connect(SpinBox2_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
335 //To Connect preview check box
336 connectPreviewControl();
338 ConstructorsClicked(0);
339 SelectionIntoArgument();
340 onActionClicked(MOVE_ELEMS_BUTTON);
343 //=================================================================================
344 // function : ~SMESHGUI_TranslationDlg()
345 // purpose : Destroys the object and frees any allocated resources
346 //=================================================================================
347 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
350 myFilterDlg->setParent( 0 );
356 //=================================================================================
359 //=================================================================================
360 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
364 myEditCurrentArgument = 0;
365 LineEditElements->clear();
369 buttonOk->setEnabled(false);
370 buttonApply->setEnabled(false);
373 myMesh = SMESH::SMESH_Mesh::_nil();
376 SpinBox1_1->SetValue(0.0);
377 SpinBox1_2->SetValue(0.0);
378 SpinBox1_3->SetValue(0.0);
379 SpinBox2_1->SetValue(0.0);
380 SpinBox2_2->SetValue(0.0);
381 SpinBox2_3->SetValue(0.0);
383 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
384 CheckBoxMesh->setChecked(false);
385 // MakeGroupsCheck->setChecked(false);
386 // MakeGroupsCheck->setEnabled(false);
387 myPreviewCheckBox->setChecked(false);
388 onDisplaySimulation(false);
393 //=================================================================================
394 // function : ConstructorsClicked()
395 // purpose : Radio button management
396 //=================================================================================
397 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
399 disconnect(mySelectionMgr, 0, this, 0);
401 switch (constructorId) {
404 TextLabel1->setText(tr("SMESH_POINT_1"));
405 TextLabel1_1->setText(tr("SMESH_X"));
406 TextLabel1_2->setText(tr("SMESH_Y"));
407 TextLabel1_3->setText(tr("SMESH_Z"));
409 SelectButton1->show();
411 SelectButton2->show();
412 TextLabel2_1->show();
414 TextLabel2_2->show();
416 TextLabel2_3->show();
422 TextLabel1->setText(tr("SMESH_VECTOR"));
423 TextLabel1_1->setText(tr("SMESH_DX"));
424 TextLabel1_2->setText(tr("SMESH_DY"));
425 TextLabel1_3->setText(tr("SMESH_DZ"));
427 SelectButton1->hide();
429 SelectButton2->hide();
430 TextLabel2_1->hide();
432 TextLabel2_2->hide();
434 TextLabel2_3->hide();
440 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
441 SMESH::SetPointRepresentation(false);
442 if (!CheckBoxMesh->isChecked())
443 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
444 aViewWindow->SetSelectionMode( CellSelection );
447 myEditCurrentArgument = (QWidget*)LineEditElements;
448 LineEditElements->setFocus();
450 if (CheckBoxMesh->isChecked())
453 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
455 onDisplaySimulation(true);
457 QApplication::instance()->processEvents();
462 //=================================================================================
463 // function : ClickOnApply()
465 //=================================================================================
466 bool SMESHGUI_TranslationDlg::ClickOnApply()
468 if (mySMESHGUI->isActiveStudyLocked())
474 if (myNbOkElements) {
475 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
477 SMESH::long_array_var anElementsId = new SMESH::long_array;
479 anElementsId->length(aListElementsId.count());
480 for (int i = 0; i < aListElementsId.count(); i++)
481 anElementsId[i] = aListElementsId[i].toInt();
483 SMESH::DirStruct aVector;
484 if (GetConstructorId() == 0) {
485 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
486 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
487 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
488 } else if (GetConstructorId() == 1) {
489 aVector.PS.x = SpinBox1_1->GetValue();
490 aVector.PS.y = SpinBox1_2->GetValue();
491 aVector.PS.z = SpinBox1_3->GetValue();
494 QStringList aParameters;
495 aParameters << SpinBox1_1->text();
496 if (GetConstructorId() == 0)
497 aParameters << SpinBox2_1->text();
498 aParameters << SpinBox1_2->text();
499 if (GetConstructorId() == 0)
500 aParameters << SpinBox2_2->text();
501 aParameters << SpinBox1_3->text();
502 if (GetConstructorId() == 0)
503 aParameters << SpinBox2_3->text();
505 int actionButton = ActionGroup->checkedId();
506 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
508 SUIT_OverrideCursor aWaitCursor;
509 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
510 switch ( actionButton ) {
511 case MOVE_ELEMS_BUTTON:
512 if(CheckBoxMesh->isChecked())
513 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
515 aMeshEditor->Translate(anElementsId, aVector, false);
516 if( !myMesh->_is_nil())
517 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
519 case COPY_ELEMS_BUTTON:
521 SMESH::ListOfGroups_var groups;
522 if(CheckBoxMesh->isChecked())
523 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
525 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
528 if(CheckBoxMesh->isChecked())
529 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
531 aMeshEditor->Translate(anElementsId, aVector, true);
533 if( !myMesh->_is_nil())
534 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
536 case MAKE_MESH_BUTTON:
537 SMESH::SMESH_Mesh_var mesh;
538 if (CheckBoxMesh->isChecked())
539 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
540 LineEditNewMesh->text().toLatin1().data());
542 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
543 LineEditNewMesh->text().toLatin1().data());
544 if (!mesh->_is_nil()) {
545 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
546 #ifdef WITHGENERICOBJ
547 // obj has been published in study. Its refcount has been incremented.
548 // It is safe to decrement its refcount
549 // so that it will be destroyed when the entry in study will be removed
558 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
559 actionButton == MAKE_MESH_BUTTON )
560 mySMESHGUI->updateObjBrowser(true); // new groups may appear
562 ConstructorsClicked(GetConstructorId());
563 mySelectedObject = SMESH::SMESH_IDSource::_nil();
564 SelectionIntoArgument();
566 SMESHGUI::Modified();
572 //=================================================================================
573 // function : ClickOnOk()
575 //=================================================================================
576 void SMESHGUI_TranslationDlg::ClickOnOk()
582 //=================================================================================
583 // function : ClickOnCancel()
585 //=================================================================================
586 void SMESHGUI_TranslationDlg::ClickOnCancel()
588 disconnect(mySelectionMgr, 0, this, 0);
589 mySelectionMgr->clearFilters();
590 //mySelectionMgr->clearSelected();
591 if (SMESH::GetCurrentVtkView()) {
592 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
593 SMESH::SetPointRepresentation(false);
595 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
596 aViewWindow->SetSelectionMode( ActorSelection );
597 mySMESHGUI->ResetState();
601 //=================================================================================
602 // function : ClickOnHelp()
604 //=================================================================================
605 void SMESHGUI_TranslationDlg::ClickOnHelp()
607 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
609 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
613 platform = "winapplication";
615 platform = "application";
617 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
618 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
619 arg(app->resourceMgr()->stringValue("ExternalBrowser",
621 arg(myHelpFileName));
625 //=======================================================================
626 // function : onTextChange()
628 //=======================================================================
629 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
631 QLineEdit* send = (QLineEdit*)sender();
634 BusyLocker lock( myBusy );
636 if (send == LineEditElements)
639 buttonOk->setEnabled(false);
640 buttonApply->setEnabled(false);
642 // hilight entered elements
643 SMDS_Mesh* aMesh = 0;
645 aMesh = myActor->GetObject()->GetMesh();
648 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
650 TColStd_MapOfInteger newIndices;
652 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
654 if (send == LineEditElements) {
655 for (int i = 0; i < aListId.count(); i++) {
656 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
658 newIndices.Add(e->GetID());
663 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
664 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
665 aViewWindow->highlight( anIO, true, true );
667 myElementsId = theNewText;
670 if (myNbOkElements) {
671 buttonOk->setEnabled(true);
672 buttonApply->setEnabled(true);
676 //=================================================================================
677 // function : SelectionIntoArgument()
678 // purpose : Called when selection as changed or other case
679 //=================================================================================
680 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
683 BusyLocker lock( myBusy );
686 QString aString = "";
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
689 LineEditElements->setText(aString);
691 buttonOk->setEnabled(false);
692 buttonApply->setEnabled(false);
695 if (!GroupButtons->isEnabled()) // inactive
700 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
702 int nbSel = aList.Extent();
706 Handle(SALOME_InteractiveObject) IO = aList.First();
707 myMesh = SMESH::GetMeshByIO(IO);
708 if (myMesh->_is_nil())
711 myActor = SMESH::FindActorByObject(myMesh);
713 myActor = SMESH::FindActorByEntry(IO->getEntry());
715 if (!myActor && !CheckBoxMesh->isChecked())
720 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
723 // MakeGroups is available if there are groups and "Copy"
724 if ( myMesh->NbGroups() == 0 ) {
725 MakeGroupsCheck->setChecked(false);
726 MakeGroupsCheck->setEnabled(false);
728 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
729 MakeGroupsCheck->setEnabled(true);
732 if (CheckBoxMesh->isChecked()) {
733 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
735 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
736 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
742 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
746 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
747 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
749 myElementsId += QString(" %1").arg(i);
753 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
755 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
757 // get IDs from submesh
758 SMESH::long_array_var anElementsIds = new SMESH::long_array;
759 anElementsIds = aSubMesh->GetElementsId();
760 for (int i = 0; i < anElementsIds->length(); i++) {
761 myElementsId += QString(" %1").arg(anElementsIds[i]);
763 aNbUnits = anElementsIds->length();
766 SMESH::SMESH_GroupBase_var aGroup =
767 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
768 if (aGroup->_is_nil())
771 // get IDs from smesh group
772 SMESH::long_array_var anElementsIds = new SMESH::long_array;
773 anElementsIds = aGroup->GetListOfID();
774 for (int i = 0; i < anElementsIds->length(); i++) {
775 myElementsId += QString(" %1").arg(anElementsIds[i]);
777 aNbUnits = anElementsIds->length();
781 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
782 myElementsId = aString;
787 myNbOkElements = true;
789 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
793 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
797 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
805 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
806 SpinBox1_1->SetValue(x);
807 SpinBox1_2->SetValue(y);
808 SpinBox1_3->SetValue(z);
809 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
810 SpinBox2_1->SetValue(x);
811 SpinBox2_2->SetValue(y);
812 SpinBox2_3->SetValue(z);
816 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
817 LineEditElements->setText(aString);
818 LineEditElements->repaint();
819 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
820 LineEditElements->setEnabled(true);
825 if (myNbOkElements) {
826 buttonOk->setEnabled(true);
827 buttonApply->setEnabled(true);
829 onDisplaySimulation(true);
832 //=================================================================================
833 // function : SetEditCurrentArgument()
835 //=================================================================================
836 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
838 QPushButton* send = (QPushButton*)sender();
840 disconnect(mySelectionMgr, 0, this, 0);
841 mySelectionMgr->clearSelected();
842 mySelectionMgr->clearFilters();
844 if (send == SelectElementsButton) {
845 myEditCurrentArgument = (QWidget*)LineEditElements;
846 SMESH::SetPointRepresentation(false);
847 if (CheckBoxMesh->isChecked()) {
848 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
849 aViewWindow->SetSelectionMode( ActorSelection );
850 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
853 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
854 aViewWindow->SetSelectionMode( CellSelection );
856 } else if (send == SelectButton1) {
857 myEditCurrentArgument = (QWidget*)SpinBox1_1;
858 SMESH::SetPointRepresentation(true);
860 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
861 aViewWindow->SetSelectionMode( NodeSelection );
862 } else if (send == SelectButton2) {
863 myEditCurrentArgument = (QWidget*)SpinBox2_1;
864 SMESH::SetPointRepresentation(true);
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->SetSelectionMode( NodeSelection );
870 myEditCurrentArgument->setFocus();
871 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
872 SelectionIntoArgument();
875 //=================================================================================
876 // function : DeactivateActiveDialog()
878 //=================================================================================
879 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
881 if (ConstructorsBox->isEnabled()) {
882 ConstructorsBox->setEnabled(false);
883 GroupArguments->setEnabled(false);
884 GroupButtons->setEnabled(false);
885 mySMESHGUI->ResetState();
886 mySMESHGUI->SetActiveDialogBox(0);
890 //=================================================================================
891 // function : ActivateThisDialog()
893 //=================================================================================
894 void SMESHGUI_TranslationDlg::ActivateThisDialog()
896 /* Emit a signal to deactivate the active dialog */
897 mySMESHGUI->EmitSignalDeactivateDialog();
898 ConstructorsBox->setEnabled(true);
899 GroupArguments->setEnabled(true);
900 GroupButtons->setEnabled(true);
902 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode( CellSelection );
907 SelectionIntoArgument();
910 //=================================================================================
911 // function : enterEvent()
913 //=================================================================================
914 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
916 if (!ConstructorsBox->isEnabled())
917 ActivateThisDialog();
920 //=================================================================================
921 // function : closeEvent()
923 //=================================================================================
924 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
926 /* same than click on cancel button */
930 //=======================================================================
931 //function : hideEvent
932 //purpose : caused by ESC key
933 //=======================================================================
934 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
940 //=======================================================================
941 //function : onSelectMesh
943 //=======================================================================
944 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
947 TextLabelElements->setText(tr("SMESH_NAME"));
949 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
950 myFilterBtn->setEnabled(!toSelectMesh);
952 if (myEditCurrentArgument != LineEditElements) {
953 LineEditElements->clear();
957 mySelectionMgr->clearFilters();
958 SMESH::SetPointRepresentation(false);
961 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
962 aViewWindow->SetSelectionMode( ActorSelection );
963 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
964 LineEditElements->setReadOnly(true);
965 LineEditElements->setValidator(0);
967 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
968 aViewWindow->SetSelectionMode( CellSelection );
969 LineEditElements->setReadOnly(false);
970 LineEditElements->setValidator(myIdValidator);
971 onTextChange(LineEditElements->text());
975 SelectionIntoArgument();
978 //=======================================================================
979 //function : onActionClicked
980 //purpose : slot called when an action type changed
981 //=======================================================================
983 void SMESHGUI_TranslationDlg::onActionClicked(int button)
986 case MOVE_ELEMS_BUTTON:
987 MakeGroupsCheck->setEnabled(false);
988 LineEditNewMesh->setEnabled(false);
990 case COPY_ELEMS_BUTTON:
991 LineEditNewMesh->setEnabled(false);
992 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
993 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
994 MakeGroupsCheck->setEnabled(true);
996 MakeGroupsCheck->setEnabled(false);
998 case MAKE_MESH_BUTTON:
999 LineEditNewMesh->setEnabled(true);
1000 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1001 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1002 MakeGroupsCheck->setEnabled(true);
1004 MakeGroupsCheck->setEnabled(false);
1008 toDisplaySimulation();
1011 //=======================================================================
1012 //function : setNewMeshName
1013 //purpose : update contents of LineEditNewMesh
1014 //=======================================================================
1016 void SMESHGUI_TranslationDlg::setNewMeshName()
1018 LineEditNewMesh->setText("");
1019 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1021 if ( CheckBoxMesh->isChecked() ) {
1022 name = LineEditElements->text();
1025 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1026 name = meshSO->GetName().c_str();
1028 if ( !name.isEmpty() )
1029 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1033 //=================================================================================
1034 // function : GetConstructorId()
1036 //=================================================================================
1037 int SMESHGUI_TranslationDlg::GetConstructorId()
1039 return GroupConstructors->checkedId();
1042 //=================================================================================
1043 // function : keyPressEvent()
1045 //=================================================================================
1046 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1048 QDialog::keyPressEvent( e );
1049 if ( e->isAccepted() )
1052 if ( e->key() == Qt::Key_F1 ) {
1058 //=================================================================================
1059 // function : setFilters()
1060 // purpose : SLOT. Called when "Filter" button pressed.
1061 //=================================================================================
1062 void SMESHGUI_TranslationDlg::setFilters()
1064 if(myMesh->_is_nil()) {
1065 SUIT_MessageBox::critical(this,
1067 tr("NO_MESH_SELECTED"));
1071 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1073 myFilterDlg->SetSelection();
1074 myFilterDlg->SetMesh( myMesh );
1075 myFilterDlg->SetSourceWg( LineEditElements );
1077 myFilterDlg->show();
1080 //=================================================================================
1081 // function : isValid
1083 //=================================================================================
1084 bool SMESHGUI_TranslationDlg::isValid()
1089 ok = SpinBox1_1->isValid( msg, true ) && ok;
1090 ok = SpinBox1_2->isValid( msg, true ) && ok;
1091 ok = SpinBox1_3->isValid( msg, true ) && ok;
1092 if (GetConstructorId() == 0) {
1093 ok = SpinBox2_1->isValid( msg, true ) && ok;
1094 ok = SpinBox2_2->isValid( msg, true ) && ok;
1095 ok = SpinBox2_3->isValid( msg, true ) && ok;
1099 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1100 if ( !msg.isEmpty() )
1102 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1108 //=================================================================================
1109 // function : onDisplaySimulation
1110 // purpose : Show/Hide preview
1111 //=================================================================================
1112 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1113 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1115 if (isValid() && myNbOkElements) {
1116 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1118 SMESH::long_array_var anElementsId = new SMESH::long_array;
1120 anElementsId->length(aListElementsId.count());
1121 for (int i = 0; i < aListElementsId.count(); i++)
1122 anElementsId[i] = aListElementsId[i].toInt();
1124 SMESH::DirStruct aVector;
1125 if (GetConstructorId() == 0) {
1126 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1127 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1128 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1129 } else if (GetConstructorId() == 1) {
1130 aVector.PS.x = SpinBox1_1->GetValue();
1131 aVector.PS.y = SpinBox1_2->GetValue();
1132 aVector.PS.z = SpinBox1_3->GetValue();
1136 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1137 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1138 SUIT_OverrideCursor aWaitCursor;
1139 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1140 if(CheckBoxMesh->isChecked())
1141 aMeshEditor->TranslateObject(mySelectedObject, aVector, copy);
1143 aMeshEditor->Translate(anElementsId, aVector, copy);
1145 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1146 mySimulation->SetData(aMeshPreviewStruct._retn());