1 // Copyright (C) 2007-2011 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>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 \brief Simple 'busy state' flag locker.
93 //! Constructor. Sets passed boolean flag to \c true.
94 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96 ~BusyLocker() { myBusy = false; }
98 bool& myBusy; //! External 'busy state' boolean flag
104 //To disable automatic genericobj management, the following line should be commented.
105 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
106 #define WITHGENERICOBJ
108 //=================================================================================
109 // class : SMESHGUI_TranslationDlg()
111 //=================================================================================
112 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
113 SMESHGUI_PreviewDlg( theModule ),
114 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
116 mySelectedObject(SMESH::SMESH_IDSource::_nil())
118 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
119 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
120 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
123 setAttribute(Qt::WA_DeleteOnClose, true);
124 setWindowTitle(tr("SMESH_TRANSLATION"));
125 setSizeGripEnabled(true);
127 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
128 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
129 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
131 /***************************************************************/
132 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
133 GroupConstructors = new QButtonGroup(this);
134 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
135 ConstructorsBoxLayout->setSpacing(SPACING);
136 ConstructorsBoxLayout->setMargin(MARGIN);
138 RadioButton1= new QRadioButton(ConstructorsBox);
139 RadioButton1->setIcon(image0);
140 RadioButton2= new QRadioButton(ConstructorsBox);
141 RadioButton2->setIcon(image1);
143 ConstructorsBoxLayout->addWidget(RadioButton1);
144 ConstructorsBoxLayout->addWidget(RadioButton2);
145 GroupConstructors->addButton(RadioButton1, 0);
146 GroupConstructors->addButton(RadioButton2, 1);
148 /***************************************************************/
149 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
150 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
151 GroupArgumentsLayout->setSpacing(SPACING);
152 GroupArgumentsLayout->setMargin(MARGIN);
154 myIdValidator = new SMESHGUI_IdValidator(this);
156 // Controls for elements selection
157 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
158 SelectElementsButton = new QPushButton(GroupArguments);
159 SelectElementsButton->setIcon(image2);
160 LineEditElements = new QLineEdit(GroupArguments);
161 LineEditElements->setValidator(myIdValidator);
162 LineEditElements->setMaxLength(-1);
163 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
164 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
166 // Control for the whole mesh selection
167 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
169 // Controls for vector and points selection
170 TextLabel1 = new QLabel(GroupArguments);
171 SelectButton1 = new QPushButton(GroupArguments);
172 SelectButton1->setIcon(image2);
174 TextLabel1_1 = new QLabel(GroupArguments);
175 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel1_2 = new QLabel(GroupArguments);
177 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel1_3 = new QLabel(GroupArguments);
179 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
181 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
182 SelectButton2 = new QPushButton(GroupArguments);
183 SelectButton2->setIcon(image2);
185 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
186 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
187 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
188 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
189 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
190 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
192 // switch of action type
193 ActionBox = new QGroupBox(GroupArguments);
194 ActionGroup = new QButtonGroup(GroupArguments);
195 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
196 ActionBoxLayout->addSpacing(SPACING);
197 ActionBoxLayout->setMargin(MARGIN);
199 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
200 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
201 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
203 ActionBoxLayout->addWidget(aMoveElements);
204 ActionBoxLayout->addWidget(aCopyElements);
205 ActionBoxLayout->addWidget(aCreateMesh);
206 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
207 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
208 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
210 // CheckBox for groups generation
211 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
212 MakeGroupsCheck->setChecked(false);
214 // Name of a mesh to create
215 LineEditNewMesh = new QLineEdit(GroupArguments);
218 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
221 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
222 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
223 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
224 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
225 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
226 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
227 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
228 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
229 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
230 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
231 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
232 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
233 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
234 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
235 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
236 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
237 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
238 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
239 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
240 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
241 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
242 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
243 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
244 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
245 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
247 /***************************************************************/
248 GroupButtons = new QGroupBox(this);
249 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
250 GroupButtonsLayout->setSpacing(SPACING);
251 GroupButtonsLayout->setMargin(MARGIN);
253 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
254 buttonOk->setAutoDefault(true);
255 buttonOk->setDefault(true);
256 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
257 buttonApply->setAutoDefault(true);
258 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
259 buttonCancel->setAutoDefault(true);
260 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
261 buttonHelp->setAutoDefault(true);
263 GroupButtonsLayout->addWidget(buttonOk);
264 GroupButtonsLayout->addSpacing(10);
265 GroupButtonsLayout->addWidget(buttonApply);
266 GroupButtonsLayout->addSpacing(10);
267 GroupButtonsLayout->addStretch();
268 GroupButtonsLayout->addWidget(buttonCancel);
269 GroupButtonsLayout->addWidget(buttonHelp);
271 /***************************************************************/
272 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
273 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
274 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
276 /* Initialisations */
277 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
280 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
282 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
284 RadioButton1->setChecked(true);
286 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
288 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
290 // Costruction of the logical filter
291 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
292 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
294 QList<SUIT_SelectionFilter*> aListOfFilters;
295 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
296 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
298 myMeshOrSubMeshOrGroupFilter =
299 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
301 myHelpFileName = "translation_page.html";
305 /* signals and slots connections */
306 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
307 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
308 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
309 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
310 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
312 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
314 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
316 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
317 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
318 /* to close dialog if study change */
319 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
320 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
321 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
322 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
324 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox2_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox2_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox2_3, 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 myEditCurrentArgument = 0;
364 LineEditElements->clear();
368 buttonOk->setEnabled(false);
369 buttonApply->setEnabled(false);
372 myMesh = SMESH::SMESH_Mesh::_nil();
375 SpinBox1_1->SetValue(0.0);
376 SpinBox1_2->SetValue(0.0);
377 SpinBox1_3->SetValue(0.0);
378 SpinBox2_1->SetValue(0.0);
379 SpinBox2_2->SetValue(0.0);
380 SpinBox2_3->SetValue(0.0);
382 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
383 CheckBoxMesh->setChecked(false);
384 // MakeGroupsCheck->setChecked(false);
385 // MakeGroupsCheck->setEnabled(false);
386 myPreviewCheckBox->setChecked(false);
387 onDisplaySimulation(false);
392 //=================================================================================
393 // function : ConstructorsClicked()
394 // purpose : Radio button management
395 //=================================================================================
396 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
398 disconnect(mySelectionMgr, 0, this, 0);
400 switch (constructorId) {
403 TextLabel1->setText(tr("SMESH_POINT_1"));
404 TextLabel1_1->setText(tr("SMESH_X"));
405 TextLabel1_2->setText(tr("SMESH_Y"));
406 TextLabel1_3->setText(tr("SMESH_Z"));
408 SelectButton1->show();
410 SelectButton2->show();
411 TextLabel2_1->show();
413 TextLabel2_2->show();
415 TextLabel2_3->show();
421 TextLabel1->setText(tr("SMESH_VECTOR"));
422 TextLabel1_1->setText(tr("SMESH_DX"));
423 TextLabel1_2->setText(tr("SMESH_DY"));
424 TextLabel1_3->setText(tr("SMESH_DZ"));
426 SelectButton1->hide();
428 SelectButton2->hide();
429 TextLabel2_1->hide();
431 TextLabel2_2->hide();
433 TextLabel2_3->hide();
439 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
440 SMESH::SetPointRepresentation(false);
441 if (!CheckBoxMesh->isChecked())
442 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
443 aViewWindow->SetSelectionMode( CellSelection );
446 myEditCurrentArgument = (QWidget*)LineEditElements;
447 LineEditElements->setFocus();
449 if (CheckBoxMesh->isChecked())
452 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
454 onDisplaySimulation(true);
456 QApplication::instance()->processEvents();
461 //=================================================================================
462 // function : ClickOnApply()
464 //=================================================================================
465 bool SMESHGUI_TranslationDlg::ClickOnApply()
467 if (mySMESHGUI->isActiveStudyLocked())
473 if (myNbOkElements) {
474 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
476 SMESH::long_array_var anElementsId = new SMESH::long_array;
478 anElementsId->length(aListElementsId.count());
479 for (int i = 0; i < aListElementsId.count(); i++)
480 anElementsId[i] = aListElementsId[i].toInt();
482 SMESH::DirStruct aVector;
483 if (GetConstructorId() == 0) {
484 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
485 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
486 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
487 } else if (GetConstructorId() == 1) {
488 aVector.PS.x = SpinBox1_1->GetValue();
489 aVector.PS.y = SpinBox1_2->GetValue();
490 aVector.PS.z = SpinBox1_3->GetValue();
493 QStringList aParameters;
494 aParameters << SpinBox1_1->text();
495 if (GetConstructorId() == 0)
496 aParameters << SpinBox2_1->text();
497 aParameters << SpinBox1_2->text();
498 if (GetConstructorId() == 0)
499 aParameters << SpinBox2_2->text();
500 aParameters << SpinBox1_3->text();
501 if (GetConstructorId() == 0)
502 aParameters << SpinBox2_3->text();
504 int actionButton = ActionGroup->checkedId();
505 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
506 QStringList anEntryList;
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 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
547 anEntryList.append( aSObject->GetID().c_str() );
548 #ifdef WITHGENERICOBJ
549 // obj has been published in study. Its refcount has been incremented.
550 // It is safe to decrement its refcount
551 // so that it will be destroyed when the entry in study will be removed
560 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
561 actionButton == MAKE_MESH_BUTTON ) {
562 mySMESHGUI->updateObjBrowser(true); // new groups may appear
563 if( LightApp_Application* anApp =
564 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
565 anApp->browseObjects( anEntryList, isApplyAndClose() );
569 ConstructorsClicked(GetConstructorId());
570 mySelectedObject = SMESH::SMESH_IDSource::_nil();
571 SelectionIntoArgument();
573 SMESHGUI::Modified();
579 //=================================================================================
580 // function : ClickOnOk()
582 //=================================================================================
583 void SMESHGUI_TranslationDlg::ClickOnOk()
585 setIsApplyAndClose( true );
590 //=================================================================================
591 // function : ClickOnCancel()
593 //=================================================================================
594 void SMESHGUI_TranslationDlg::ClickOnCancel()
596 disconnect(mySelectionMgr, 0, this, 0);
597 mySelectionMgr->clearFilters();
598 //mySelectionMgr->clearSelected();
599 if (SMESH::GetCurrentVtkView()) {
600 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
601 SMESH::SetPointRepresentation(false);
603 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
604 aViewWindow->SetSelectionMode( ActorSelection );
605 mySMESHGUI->ResetState();
609 //=================================================================================
610 // function : ClickOnHelp()
612 //=================================================================================
613 void SMESHGUI_TranslationDlg::ClickOnHelp()
615 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
617 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
621 platform = "winapplication";
623 platform = "application";
625 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
626 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
627 arg(app->resourceMgr()->stringValue("ExternalBrowser",
629 arg(myHelpFileName));
633 //=======================================================================
634 // function : onTextChange()
636 //=======================================================================
637 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
639 QLineEdit* send = (QLineEdit*)sender();
642 BusyLocker lock( myBusy );
644 if (send == LineEditElements)
647 buttonOk->setEnabled(false);
648 buttonApply->setEnabled(false);
650 // hilight entered elements
651 SMDS_Mesh* aMesh = 0;
653 aMesh = myActor->GetObject()->GetMesh();
656 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
658 TColStd_MapOfInteger newIndices;
660 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
662 if (send == LineEditElements) {
663 for (int i = 0; i < aListId.count(); i++) {
664 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
666 newIndices.Add(e->GetID());
671 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
672 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
673 aViewWindow->highlight( anIO, true, true );
675 myElementsId = theNewText;
678 if (myNbOkElements) {
679 buttonOk->setEnabled(true);
680 buttonApply->setEnabled(true);
684 //=================================================================================
685 // function : SelectionIntoArgument()
686 // purpose : Called when selection as changed or other case
687 //=================================================================================
688 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
691 BusyLocker lock( myBusy );
694 QString aString = "";
696 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
697 LineEditElements->setText(aString);
699 buttonOk->setEnabled(false);
700 buttonApply->setEnabled(false);
703 if (!GroupButtons->isEnabled()) // inactive
708 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
710 int nbSel = aList.Extent();
714 Handle(SALOME_InteractiveObject) IO = aList.First();
715 myMesh = SMESH::GetMeshByIO(IO);
716 if (myMesh->_is_nil())
719 myActor = SMESH::FindActorByObject(myMesh);
721 myActor = SMESH::FindActorByEntry(IO->getEntry());
723 if (!myActor && !CheckBoxMesh->isChecked())
728 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
731 // MakeGroups is available if there are groups and "Copy"
732 if ( myMesh->NbGroups() == 0 ) {
733 MakeGroupsCheck->setChecked(false);
734 MakeGroupsCheck->setEnabled(false);
736 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
737 MakeGroupsCheck->setEnabled(true);
740 if (CheckBoxMesh->isChecked()) {
741 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
743 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
744 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
750 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
754 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
755 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
757 myElementsId += QString(" %1").arg(i);
761 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
763 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
765 // get IDs from submesh
766 SMESH::long_array_var anElementsIds = new SMESH::long_array;
767 anElementsIds = aSubMesh->GetElementsId();
768 for (int i = 0; i < anElementsIds->length(); i++) {
769 myElementsId += QString(" %1").arg(anElementsIds[i]);
771 aNbUnits = anElementsIds->length();
774 SMESH::SMESH_GroupBase_var aGroup =
775 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
776 if (aGroup->_is_nil())
779 // get IDs from smesh group
780 SMESH::long_array_var anElementsIds = new SMESH::long_array;
781 anElementsIds = aGroup->GetListOfID();
782 for (int i = 0; i < anElementsIds->length(); i++) {
783 myElementsId += QString(" %1").arg(anElementsIds[i]);
785 aNbUnits = anElementsIds->length();
789 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
790 myElementsId = aString;
795 myNbOkElements = true;
797 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
801 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
805 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
813 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
814 SpinBox1_1->SetValue(x);
815 SpinBox1_2->SetValue(y);
816 SpinBox1_3->SetValue(z);
817 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
818 SpinBox2_1->SetValue(x);
819 SpinBox2_2->SetValue(y);
820 SpinBox2_3->SetValue(z);
824 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
825 LineEditElements->setText(aString);
826 LineEditElements->repaint();
827 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
828 LineEditElements->setEnabled(true);
833 if (myNbOkElements) {
834 buttonOk->setEnabled(true);
835 buttonApply->setEnabled(true);
837 onDisplaySimulation(true);
840 //=================================================================================
841 // function : SetEditCurrentArgument()
843 //=================================================================================
844 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
846 QPushButton* send = (QPushButton*)sender();
848 disconnect(mySelectionMgr, 0, this, 0);
849 mySelectionMgr->clearSelected();
850 mySelectionMgr->clearFilters();
852 if (send == SelectElementsButton) {
853 myEditCurrentArgument = (QWidget*)LineEditElements;
854 SMESH::SetPointRepresentation(false);
855 if (CheckBoxMesh->isChecked()) {
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode( ActorSelection );
858 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
861 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
862 aViewWindow->SetSelectionMode( CellSelection );
864 } else if (send == SelectButton1) {
865 myEditCurrentArgument = (QWidget*)SpinBox1_1;
866 SMESH::SetPointRepresentation(true);
868 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
869 aViewWindow->SetSelectionMode( NodeSelection );
870 } else if (send == SelectButton2) {
871 myEditCurrentArgument = (QWidget*)SpinBox2_1;
872 SMESH::SetPointRepresentation(true);
874 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
875 aViewWindow->SetSelectionMode( NodeSelection );
878 myEditCurrentArgument->setFocus();
879 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
880 SelectionIntoArgument();
883 //=================================================================================
884 // function : DeactivateActiveDialog()
886 //=================================================================================
887 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
889 if (ConstructorsBox->isEnabled()) {
890 ConstructorsBox->setEnabled(false);
891 GroupArguments->setEnabled(false);
892 GroupButtons->setEnabled(false);
893 mySMESHGUI->ResetState();
894 mySMESHGUI->SetActiveDialogBox(0);
898 //=================================================================================
899 // function : ActivateThisDialog()
901 //=================================================================================
902 void SMESHGUI_TranslationDlg::ActivateThisDialog()
904 /* Emit a signal to deactivate the active dialog */
905 mySMESHGUI->EmitSignalDeactivateDialog();
906 ConstructorsBox->setEnabled(true);
907 GroupArguments->setEnabled(true);
908 GroupButtons->setEnabled(true);
910 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
912 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
913 aViewWindow->SetSelectionMode( CellSelection );
915 SelectionIntoArgument();
918 //=================================================================================
919 // function : enterEvent()
921 //=================================================================================
922 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
924 if (!ConstructorsBox->isEnabled())
925 ActivateThisDialog();
928 //=================================================================================
929 // function : closeEvent()
931 //=================================================================================
932 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
934 /* same than click on cancel button */
938 //=======================================================================
939 //function : hideEvent
940 //purpose : caused by ESC key
941 //=======================================================================
942 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
948 //=======================================================================
949 //function : onSelectMesh
951 //=======================================================================
952 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
955 TextLabelElements->setText(tr("SMESH_NAME"));
957 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
958 myFilterBtn->setEnabled(!toSelectMesh);
960 if (myEditCurrentArgument != LineEditElements) {
961 LineEditElements->clear();
965 mySelectionMgr->clearFilters();
966 SMESH::SetPointRepresentation(false);
969 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
970 aViewWindow->SetSelectionMode( ActorSelection );
971 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
972 LineEditElements->setReadOnly(true);
973 LineEditElements->setValidator(0);
975 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
976 aViewWindow->SetSelectionMode( CellSelection );
977 LineEditElements->setReadOnly(false);
978 LineEditElements->setValidator(myIdValidator);
979 onTextChange(LineEditElements->text());
983 SelectionIntoArgument();
986 //=======================================================================
987 //function : onActionClicked
988 //purpose : slot called when an action type changed
989 //=======================================================================
991 void SMESHGUI_TranslationDlg::onActionClicked(int button)
994 case MOVE_ELEMS_BUTTON:
995 MakeGroupsCheck->setEnabled(false);
996 LineEditNewMesh->setEnabled(false);
998 case COPY_ELEMS_BUTTON:
999 LineEditNewMesh->setEnabled(false);
1000 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1001 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1002 MakeGroupsCheck->setEnabled(true);
1004 MakeGroupsCheck->setEnabled(false);
1006 case MAKE_MESH_BUTTON:
1007 LineEditNewMesh->setEnabled(true);
1008 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1009 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
1010 MakeGroupsCheck->setEnabled(true);
1012 MakeGroupsCheck->setEnabled(false);
1016 toDisplaySimulation();
1019 //=======================================================================
1020 //function : setNewMeshName
1021 //purpose : update contents of LineEditNewMesh
1022 //=======================================================================
1024 void SMESHGUI_TranslationDlg::setNewMeshName()
1026 LineEditNewMesh->setText("");
1027 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
1029 if ( CheckBoxMesh->isChecked() ) {
1030 name = LineEditElements->text();
1033 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1034 name = meshSO->GetName().c_str();
1036 if ( !name.isEmpty() )
1037 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1041 //=================================================================================
1042 // function : GetConstructorId()
1044 //=================================================================================
1045 int SMESHGUI_TranslationDlg::GetConstructorId()
1047 return GroupConstructors->checkedId();
1050 //=================================================================================
1051 // function : keyPressEvent()
1053 //=================================================================================
1054 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1056 QDialog::keyPressEvent( e );
1057 if ( e->isAccepted() )
1060 if ( e->key() == Qt::Key_F1 ) {
1066 //=================================================================================
1067 // function : setFilters()
1068 // purpose : SLOT. Called when "Filter" button pressed.
1069 //=================================================================================
1070 void SMESHGUI_TranslationDlg::setFilters()
1072 if(myMesh->_is_nil()) {
1073 SUIT_MessageBox::critical(this,
1075 tr("NO_MESH_SELECTED"));
1079 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1081 myFilterDlg->SetSelection();
1082 myFilterDlg->SetMesh( myMesh );
1083 myFilterDlg->SetSourceWg( LineEditElements );
1085 myFilterDlg->show();
1088 //=================================================================================
1089 // function : isValid
1091 //=================================================================================
1092 bool SMESHGUI_TranslationDlg::isValid()
1097 ok = SpinBox1_1->isValid( msg, true ) && ok;
1098 ok = SpinBox1_2->isValid( msg, true ) && ok;
1099 ok = SpinBox1_3->isValid( msg, true ) && ok;
1100 if (GetConstructorId() == 0) {
1101 ok = SpinBox2_1->isValid( msg, true ) && ok;
1102 ok = SpinBox2_2->isValid( msg, true ) && ok;
1103 ok = SpinBox2_3->isValid( msg, true ) && ok;
1107 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1108 if ( !msg.isEmpty() )
1110 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1116 //=================================================================================
1117 // function : onDisplaySimulation
1118 // purpose : Show/Hide preview
1119 //=================================================================================
1120 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1121 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1123 if (isValid() && myNbOkElements) {
1124 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1126 SMESH::long_array_var anElementsId = new SMESH::long_array;
1128 anElementsId->length(aListElementsId.count());
1129 for (int i = 0; i < aListElementsId.count(); i++)
1130 anElementsId[i] = aListElementsId[i].toInt();
1132 SMESH::DirStruct aVector;
1133 if (GetConstructorId() == 0) {
1134 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1135 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1136 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1137 } else if (GetConstructorId() == 1) {
1138 aVector.PS.x = SpinBox1_1->GetValue();
1139 aVector.PS.y = SpinBox1_2->GetValue();
1140 aVector.PS.z = SpinBox1_3->GetValue();
1144 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1145 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1146 SUIT_OverrideCursor aWaitCursor;
1147 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1148 if(CheckBoxMesh->isChecked())
1149 aMeshEditor->TranslateObject(mySelectedObject, aVector, copy);
1151 aMeshEditor->Translate(anElementsId, aVector, copy);
1153 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1154 mySimulation->SetData(aMeshPreviewStruct._retn());