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() );
507 QStringList anEntryList;
509 SUIT_OverrideCursor aWaitCursor;
510 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
511 switch ( actionButton ) {
512 case MOVE_ELEMS_BUTTON:
513 if(CheckBoxMesh->isChecked())
514 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
516 aMeshEditor->Translate(anElementsId, aVector, false);
517 if( !myMesh->_is_nil())
518 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
520 case COPY_ELEMS_BUTTON:
522 SMESH::ListOfGroups_var groups;
523 if(CheckBoxMesh->isChecked())
524 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
526 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
529 if(CheckBoxMesh->isChecked())
530 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
532 aMeshEditor->Translate(anElementsId, aVector, true);
534 if( !myMesh->_is_nil())
535 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
537 case MAKE_MESH_BUTTON:
538 SMESH::SMESH_Mesh_var mesh;
539 if (CheckBoxMesh->isChecked())
540 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
541 LineEditNewMesh->text().toLatin1().data());
543 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
544 LineEditNewMesh->text().toLatin1().data());
545 if (!mesh->_is_nil()) {
546 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
547 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
548 anEntryList.append( aSObject->GetID().c_str() );
549 #ifdef WITHGENERICOBJ
550 // obj has been published in study. Its refcount has been incremented.
551 // It is safe to decrement its refcount
552 // so that it will be destroyed when the entry in study will be removed
561 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
562 actionButton == MAKE_MESH_BUTTON ) {
563 mySMESHGUI->updateObjBrowser(true); // new groups may appear
564 if( LightApp_Application* anApp =
565 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
566 anApp->browseObjects( anEntryList, isApplyAndClose() );
570 ConstructorsClicked(GetConstructorId());
571 mySelectedObject = SMESH::SMESH_IDSource::_nil();
572 SelectionIntoArgument();
574 SMESHGUI::Modified();
580 //=================================================================================
581 // function : ClickOnOk()
583 //=================================================================================
584 void SMESHGUI_TranslationDlg::ClickOnOk()
586 setIsApplyAndClose( true );
591 //=================================================================================
592 // function : ClickOnCancel()
594 //=================================================================================
595 void SMESHGUI_TranslationDlg::ClickOnCancel()
597 disconnect(mySelectionMgr, 0, this, 0);
598 mySelectionMgr->clearFilters();
599 //mySelectionMgr->clearSelected();
600 if (SMESH::GetCurrentVtkView()) {
601 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
602 SMESH::SetPointRepresentation(false);
604 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
605 aViewWindow->SetSelectionMode( ActorSelection );
606 mySMESHGUI->ResetState();
610 //=================================================================================
611 // function : ClickOnHelp()
613 //=================================================================================
614 void SMESHGUI_TranslationDlg::ClickOnHelp()
616 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
618 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
622 platform = "winapplication";
624 platform = "application";
626 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
627 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
628 arg(app->resourceMgr()->stringValue("ExternalBrowser",
630 arg(myHelpFileName));
634 //=======================================================================
635 // function : onTextChange()
637 //=======================================================================
638 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
640 QLineEdit* send = (QLineEdit*)sender();
643 BusyLocker lock( myBusy );
645 if (send == LineEditElements)
648 buttonOk->setEnabled(false);
649 buttonApply->setEnabled(false);
651 // hilight entered elements
652 SMDS_Mesh* aMesh = 0;
654 aMesh = myActor->GetObject()->GetMesh();
657 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
659 TColStd_MapOfInteger newIndices;
661 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
663 if (send == LineEditElements) {
664 for (int i = 0; i < aListId.count(); i++) {
665 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
667 newIndices.Add(e->GetID());
672 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
673 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
674 aViewWindow->highlight( anIO, true, true );
676 myElementsId = theNewText;
679 if (myNbOkElements) {
680 buttonOk->setEnabled(true);
681 buttonApply->setEnabled(true);
685 //=================================================================================
686 // function : SelectionIntoArgument()
687 // purpose : Called when selection as changed or other case
688 //=================================================================================
689 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
692 BusyLocker lock( myBusy );
695 QString aString = "";
697 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
698 LineEditElements->setText(aString);
700 buttonOk->setEnabled(false);
701 buttonApply->setEnabled(false);
704 if (!GroupButtons->isEnabled()) // inactive
709 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
711 int nbSel = aList.Extent();
715 Handle(SALOME_InteractiveObject) IO = aList.First();
716 myMesh = SMESH::GetMeshByIO(IO);
717 if (myMesh->_is_nil())
720 myActor = SMESH::FindActorByObject(myMesh);
722 myActor = SMESH::FindActorByEntry(IO->getEntry());
724 if (!myActor && !CheckBoxMesh->isChecked())
729 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
732 // MakeGroups is available if there are groups and "Copy"
733 if ( myMesh->NbGroups() == 0 ) {
734 MakeGroupsCheck->setChecked(false);
735 MakeGroupsCheck->setEnabled(false);
737 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
738 MakeGroupsCheck->setEnabled(true);
741 if (CheckBoxMesh->isChecked()) {
742 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
744 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
745 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
751 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
755 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
756 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
758 myElementsId += QString(" %1").arg(i);
762 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
764 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
766 // get IDs from submesh
767 SMESH::long_array_var anElementsIds = new SMESH::long_array;
768 anElementsIds = aSubMesh->GetElementsId();
769 for (int i = 0; i < anElementsIds->length(); i++) {
770 myElementsId += QString(" %1").arg(anElementsIds[i]);
772 aNbUnits = anElementsIds->length();
775 SMESH::SMESH_GroupBase_var aGroup =
776 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
777 if (aGroup->_is_nil())
780 // get IDs from smesh group
781 SMESH::long_array_var anElementsIds = new SMESH::long_array;
782 anElementsIds = aGroup->GetListOfID();
783 for (int i = 0; i < anElementsIds->length(); i++) {
784 myElementsId += QString(" %1").arg(anElementsIds[i]);
786 aNbUnits = anElementsIds->length();
790 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
791 myElementsId = aString;
796 myNbOkElements = true;
798 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
802 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
806 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
814 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
815 SpinBox1_1->SetValue(x);
816 SpinBox1_2->SetValue(y);
817 SpinBox1_3->SetValue(z);
818 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
819 SpinBox2_1->SetValue(x);
820 SpinBox2_2->SetValue(y);
821 SpinBox2_3->SetValue(z);
825 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
826 LineEditElements->setText(aString);
827 LineEditElements->repaint();
828 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
829 LineEditElements->setEnabled(true);
834 if (myNbOkElements) {
835 buttonOk->setEnabled(true);
836 buttonApply->setEnabled(true);
838 onDisplaySimulation(true);
841 //=================================================================================
842 // function : SetEditCurrentArgument()
844 //=================================================================================
845 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
847 QPushButton* send = (QPushButton*)sender();
849 disconnect(mySelectionMgr, 0, this, 0);
850 mySelectionMgr->clearSelected();
851 mySelectionMgr->clearFilters();
853 if (send == SelectElementsButton) {
854 myEditCurrentArgument = (QWidget*)LineEditElements;
855 SMESH::SetPointRepresentation(false);
856 if (CheckBoxMesh->isChecked()) {
857 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
858 aViewWindow->SetSelectionMode( ActorSelection );
859 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
862 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
863 aViewWindow->SetSelectionMode( CellSelection );
865 } else if (send == SelectButton1) {
866 myEditCurrentArgument = (QWidget*)SpinBox1_1;
867 SMESH::SetPointRepresentation(true);
869 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
870 aViewWindow->SetSelectionMode( NodeSelection );
871 } else if (send == SelectButton2) {
872 myEditCurrentArgument = (QWidget*)SpinBox2_1;
873 SMESH::SetPointRepresentation(true);
875 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
876 aViewWindow->SetSelectionMode( NodeSelection );
879 myEditCurrentArgument->setFocus();
880 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
881 SelectionIntoArgument();
884 //=================================================================================
885 // function : DeactivateActiveDialog()
887 //=================================================================================
888 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
890 if (ConstructorsBox->isEnabled()) {
891 ConstructorsBox->setEnabled(false);
892 GroupArguments->setEnabled(false);
893 GroupButtons->setEnabled(false);
894 mySMESHGUI->ResetState();
895 mySMESHGUI->SetActiveDialogBox(0);
899 //=================================================================================
900 // function : ActivateThisDialog()
902 //=================================================================================
903 void SMESHGUI_TranslationDlg::ActivateThisDialog()
905 /* Emit a signal to deactivate the active dialog */
906 mySMESHGUI->EmitSignalDeactivateDialog();
907 ConstructorsBox->setEnabled(true);
908 GroupArguments->setEnabled(true);
909 GroupButtons->setEnabled(true);
911 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
913 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914 aViewWindow->SetSelectionMode( CellSelection );
916 SelectionIntoArgument();
919 //=================================================================================
920 // function : enterEvent()
922 //=================================================================================
923 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
925 if (!ConstructorsBox->isEnabled())
926 ActivateThisDialog();
929 //=================================================================================
930 // function : closeEvent()
932 //=================================================================================
933 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
935 /* same than click on cancel button */
939 //=======================================================================
940 //function : hideEvent
941 //purpose : caused by ESC key
942 //=======================================================================
943 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
949 //=======================================================================
950 //function : onSelectMesh
952 //=======================================================================
953 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
956 TextLabelElements->setText(tr("SMESH_NAME"));
958 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
959 myFilterBtn->setEnabled(!toSelectMesh);
961 if (myEditCurrentArgument != LineEditElements) {
962 LineEditElements->clear();
966 mySelectionMgr->clearFilters();
967 SMESH::SetPointRepresentation(false);
970 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
971 aViewWindow->SetSelectionMode( ActorSelection );
972 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
973 LineEditElements->setReadOnly(true);
974 LineEditElements->setValidator(0);
976 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
977 aViewWindow->SetSelectionMode( CellSelection );
978 LineEditElements->setReadOnly(false);
979 LineEditElements->setValidator(myIdValidator);
980 onTextChange(LineEditElements->text());
984 SelectionIntoArgument();
987 //=======================================================================
988 //function : onActionClicked
989 //purpose : slot called when an action type changed
990 //=======================================================================
992 void SMESHGUI_TranslationDlg::onActionClicked(int button)
995 case MOVE_ELEMS_BUTTON:
996 MakeGroupsCheck->setEnabled(false);
997 LineEditNewMesh->setEnabled(false);
999 case COPY_ELEMS_BUTTON:
1000 LineEditNewMesh->setEnabled(false);
1001 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1002 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1003 MakeGroupsCheck->setEnabled(true);
1005 MakeGroupsCheck->setEnabled(false);
1007 case MAKE_MESH_BUTTON:
1008 LineEditNewMesh->setEnabled(true);
1009 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1010 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1011 MakeGroupsCheck->setEnabled(true);
1013 MakeGroupsCheck->setEnabled(false);
1017 toDisplaySimulation();
1020 //=======================================================================
1021 //function : setNewMeshName
1022 //purpose : update contents of LineEditNewMesh
1023 //=======================================================================
1025 void SMESHGUI_TranslationDlg::setNewMeshName()
1027 LineEditNewMesh->setText("");
1028 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1030 if ( CheckBoxMesh->isChecked() ) {
1031 name = LineEditElements->text();
1034 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1035 name = meshSO->GetName().c_str();
1037 if ( !name.isEmpty() )
1038 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1042 //=================================================================================
1043 // function : GetConstructorId()
1045 //=================================================================================
1046 int SMESHGUI_TranslationDlg::GetConstructorId()
1048 return GroupConstructors->checkedId();
1051 //=================================================================================
1052 // function : keyPressEvent()
1054 //=================================================================================
1055 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1057 QDialog::keyPressEvent( e );
1058 if ( e->isAccepted() )
1061 if ( e->key() == Qt::Key_F1 ) {
1067 //=================================================================================
1068 // function : setFilters()
1069 // purpose : SLOT. Called when "Filter" button pressed.
1070 //=================================================================================
1071 void SMESHGUI_TranslationDlg::setFilters()
1073 if(myMesh->_is_nil()) {
1074 SUIT_MessageBox::critical(this,
1076 tr("NO_MESH_SELECTED"));
1080 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1082 myFilterDlg->SetSelection();
1083 myFilterDlg->SetMesh( myMesh );
1084 myFilterDlg->SetSourceWg( LineEditElements );
1086 myFilterDlg->show();
1089 //=================================================================================
1090 // function : isValid
1092 //=================================================================================
1093 bool SMESHGUI_TranslationDlg::isValid()
1098 ok = SpinBox1_1->isValid( msg, true ) && ok;
1099 ok = SpinBox1_2->isValid( msg, true ) && ok;
1100 ok = SpinBox1_3->isValid( msg, true ) && ok;
1101 if (GetConstructorId() == 0) {
1102 ok = SpinBox2_1->isValid( msg, true ) && ok;
1103 ok = SpinBox2_2->isValid( msg, true ) && ok;
1104 ok = SpinBox2_3->isValid( msg, true ) && ok;
1108 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1109 if ( !msg.isEmpty() )
1111 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1117 //=================================================================================
1118 // function : onDisplaySimulation
1119 // purpose : Show/Hide preview
1120 //=================================================================================
1121 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1122 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1124 if (isValid() && myNbOkElements) {
1125 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1127 SMESH::long_array_var anElementsId = new SMESH::long_array;
1129 anElementsId->length(aListElementsId.count());
1130 for (int i = 0; i < aListElementsId.count(); i++)
1131 anElementsId[i] = aListElementsId[i].toInt();
1133 SMESH::DirStruct aVector;
1134 if (GetConstructorId() == 0) {
1135 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1136 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1137 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1138 } else if (GetConstructorId() == 1) {
1139 aVector.PS.x = SpinBox1_1->GetValue();
1140 aVector.PS.y = SpinBox1_2->GetValue();
1141 aVector.PS.z = SpinBox1_3->GetValue();
1145 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1146 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1147 SUIT_OverrideCursor aWaitCursor;
1148 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1149 if(CheckBoxMesh->isChecked())
1150 aMeshEditor->TranslateObject(mySelectedObject, aVector, copy);
1152 aMeshEditor->Translate(anElementsId, aVector, copy);
1154 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1155 mySimulation->SetData(aMeshPreviewStruct._retn());