1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_TranslationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_TranslationDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
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 (SMESH::MESHorSUBMESH);
292 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::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(reject()));
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(reject()));
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 QStringList aParameters;
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 // not supported so far
489 // aParameters << QString("%1 - %2").arg( SpinBox2_1->text() ).arg( SpinBox1_1->text() );
490 // aParameters << QString("%1 - %2").arg( SpinBox2_2->text() ).arg( SpinBox1_2->text() );
491 // aParameters << QString("%1 - %2").arg( SpinBox2_3->text() ).arg( SpinBox1_3->text() );
492 } else if (GetConstructorId() == 1) {
493 aVector.PS.x = SpinBox1_1->GetValue();
494 aVector.PS.y = SpinBox1_2->GetValue();
495 aVector.PS.z = SpinBox1_3->GetValue();
496 aParameters << SpinBox1_1->text();
497 aParameters << SpinBox1_2->text();
498 aParameters << SpinBox1_3->text();
501 int actionButton = ActionGroup->checkedId();
502 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
503 QStringList anEntryList;
505 SUIT_OverrideCursor aWaitCursor;
506 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
508 myMesh->SetParameters(aParameters.join(":").toLatin1().constData());
510 switch ( actionButton ) {
511 case MOVE_ELEMS_BUTTON:
512 if(CheckBoxMesh->isChecked())
513 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
515 aMeshEditor->Translate(anElementsId, aVector, false);
517 case COPY_ELEMS_BUTTON:
519 SMESH::ListOfGroups_var groups;
520 if(CheckBoxMesh->isChecked())
521 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
523 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
526 if(CheckBoxMesh->isChecked())
527 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
529 aMeshEditor->Translate(anElementsId, aVector, true);
532 case MAKE_MESH_BUTTON: {
533 SMESH::SMESH_Mesh_var mesh;
534 if (CheckBoxMesh->isChecked())
535 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
536 LineEditNewMesh->text().toLatin1().data());
538 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
539 LineEditNewMesh->text().toLatin1().data());
540 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
541 anEntryList.append( aSObject->GetID().c_str() );
542 #ifdef WITHGENERICOBJ
543 // obj has been published in study. Its refcount has been incremented.
544 // It is safe to decrement its refcount
545 // so that it will be destroyed when the entry in study will be removed
554 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
555 actionButton == MAKE_MESH_BUTTON ) {
556 mySMESHGUI->updateObjBrowser(true); // new groups may appear
557 if( LightApp_Application* anApp =
558 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
559 anApp->browseObjects( anEntryList, isApplyAndClose() );
563 ConstructorsClicked(GetConstructorId());
564 mySelectedObject = SMESH::SMESH_IDSource::_nil();
565 SelectionIntoArgument();
567 SMESHGUI::Modified();
573 //=================================================================================
574 // function : ClickOnOk()
576 //=================================================================================
577 void SMESHGUI_TranslationDlg::ClickOnOk()
579 setIsApplyAndClose( true );
584 //=================================================================================
585 // function : reject()
587 //=================================================================================
588 void SMESHGUI_TranslationDlg::reject()
590 disconnect(mySelectionMgr, 0, this, 0);
591 mySelectionMgr->clearFilters();
592 //mySelectionMgr->clearSelected();
593 if (SMESH::GetCurrentVtkView()) {
594 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
595 SMESH::SetPointRepresentation(false);
597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
598 aViewWindow->SetSelectionMode( ActorSelection );
599 mySMESHGUI->ResetState();
603 //=================================================================================
604 // function : ClickOnHelp()
606 //=================================================================================
607 void SMESHGUI_TranslationDlg::ClickOnHelp()
609 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
611 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
615 platform = "winapplication";
617 platform = "application";
619 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
620 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
621 arg(app->resourceMgr()->stringValue("ExternalBrowser",
623 arg(myHelpFileName));
627 //=======================================================================
628 // function : onTextChange()
630 //=======================================================================
631 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
633 QLineEdit* send = (QLineEdit*)sender();
636 BusyLocker lock( myBusy );
638 if (send == LineEditElements)
641 buttonOk->setEnabled(false);
642 buttonApply->setEnabled(false);
644 // hilight entered elements
645 SMDS_Mesh* aMesh = 0;
647 aMesh = myActor->GetObject()->GetMesh();
650 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
652 TColStd_MapOfInteger newIndices;
654 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
656 if (send == LineEditElements) {
657 for (int i = 0; i < aListId.count(); i++) {
658 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
660 newIndices.Add(e->GetID());
665 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
666 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
667 aViewWindow->highlight( anIO, true, true );
669 myElementsId = theNewText;
672 if (myNbOkElements) {
673 buttonOk->setEnabled(true);
674 buttonApply->setEnabled(true);
678 //=================================================================================
679 // function : SelectionIntoArgument()
680 // purpose : Called when selection as changed or other case
681 //=================================================================================
682 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
685 BusyLocker lock( myBusy );
688 QString aString = "";
690 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
691 LineEditElements->setText(aString);
693 buttonOk->setEnabled(false);
694 buttonApply->setEnabled(false);
697 if (!GroupButtons->isEnabled()) // inactive
702 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
704 int nbSel = aList.Extent();
708 Handle(SALOME_InteractiveObject) IO = aList.First();
709 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
710 if (aMesh->_is_nil())
713 SMESH_Actor* anActor = SMESH::FindActorByObject(aMesh);
715 anActor = SMESH::FindActorByEntry(IO->getEntry());
717 if (!anActor && !CheckBoxMesh->isChecked())
722 if (myEditCurrentArgument == (QWidget*)LineEditElements)
729 // MakeGroups is available if there are groups and "Copy"
730 if ( myMesh->NbGroups() == 0 ) {
731 MakeGroupsCheck->setChecked(false);
732 MakeGroupsCheck->setEnabled(false);
734 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
735 MakeGroupsCheck->setEnabled(true);
738 if (CheckBoxMesh->isChecked()) {
739 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
741 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
742 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
747 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
748 myElementsId = aString;
753 myNbOkElements = true;
755 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
759 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
763 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
771 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
772 SpinBox1_1->SetValue(x);
773 SpinBox1_2->SetValue(y);
774 SpinBox1_3->SetValue(z);
775 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
776 SpinBox2_1->SetValue(x);
777 SpinBox2_2->SetValue(y);
778 SpinBox2_3->SetValue(z);
782 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
783 LineEditElements->setText(aString);
784 LineEditElements->repaint();
785 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
786 LineEditElements->setEnabled(true);
791 if (myNbOkElements) {
792 buttonOk->setEnabled(true);
793 buttonApply->setEnabled(true);
795 onDisplaySimulation(true);
798 //=================================================================================
799 // function : SetEditCurrentArgument()
801 //=================================================================================
802 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
804 QPushButton* send = (QPushButton*)sender();
806 disconnect(mySelectionMgr, 0, this, 0);
807 mySelectionMgr->clearSelected();
808 mySelectionMgr->clearFilters();
810 if (send == SelectElementsButton) {
811 myEditCurrentArgument = (QWidget*)LineEditElements;
812 SMESH::SetPointRepresentation(false);
813 if (CheckBoxMesh->isChecked()) {
814 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815 aViewWindow->SetSelectionMode( ActorSelection );
816 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode( CellSelection );
822 } else if (send == SelectButton1) {
823 myEditCurrentArgument = (QWidget*)SpinBox1_1;
824 SMESH::SetPointRepresentation(true);
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode( NodeSelection );
828 } else if (send == SelectButton2) {
829 myEditCurrentArgument = (QWidget*)SpinBox2_1;
830 SMESH::SetPointRepresentation(true);
832 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
833 aViewWindow->SetSelectionMode( NodeSelection );
836 myEditCurrentArgument->setFocus();
837 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
838 SelectionIntoArgument();
841 //=================================================================================
842 // function : DeactivateActiveDialog()
844 //=================================================================================
845 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
847 if (ConstructorsBox->isEnabled()) {
848 ConstructorsBox->setEnabled(false);
849 GroupArguments->setEnabled(false);
850 GroupButtons->setEnabled(false);
851 mySMESHGUI->ResetState();
852 mySMESHGUI->SetActiveDialogBox(0);
856 //=================================================================================
857 // function : ActivateThisDialog()
859 //=================================================================================
860 void SMESHGUI_TranslationDlg::ActivateThisDialog()
862 /* Emit a signal to deactivate the active dialog */
863 mySMESHGUI->EmitSignalDeactivateDialog();
864 ConstructorsBox->setEnabled(true);
865 GroupArguments->setEnabled(true);
866 GroupButtons->setEnabled(true);
868 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
870 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
871 aViewWindow->SetSelectionMode( CellSelection );
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : enterEvent()
879 //=================================================================================
880 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
882 if (!ConstructorsBox->isEnabled())
883 ActivateThisDialog();
886 //=======================================================================
887 //function : onSelectMesh
889 //=======================================================================
890 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
893 TextLabelElements->setText(tr("SMESH_NAME"));
895 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
896 myFilterBtn->setEnabled(!toSelectMesh);
898 if (myEditCurrentArgument != LineEditElements) {
899 LineEditElements->clear();
903 mySelectionMgr->clearFilters();
904 SMESH::SetPointRepresentation(false);
907 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
908 aViewWindow->SetSelectionMode( ActorSelection );
909 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
910 LineEditElements->setReadOnly(true);
911 LineEditElements->setValidator(0);
913 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914 aViewWindow->SetSelectionMode( CellSelection );
915 LineEditElements->setReadOnly(false);
916 LineEditElements->setValidator(myIdValidator);
917 onTextChange(LineEditElements->text());
921 SelectionIntoArgument();
924 //=======================================================================
925 //function : onActionClicked
926 //purpose : slot called when an action type changed
927 //=======================================================================
929 void SMESHGUI_TranslationDlg::onActionClicked(int button)
932 case MOVE_ELEMS_BUTTON:
933 MakeGroupsCheck->setEnabled(false);
934 LineEditNewMesh->setEnabled(false);
936 case COPY_ELEMS_BUTTON:
937 LineEditNewMesh->setEnabled(false);
938 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
939 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
940 MakeGroupsCheck->setEnabled(true);
942 MakeGroupsCheck->setEnabled(false);
944 case MAKE_MESH_BUTTON:
945 LineEditNewMesh->setEnabled(true);
946 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
947 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
948 MakeGroupsCheck->setEnabled(true);
950 MakeGroupsCheck->setEnabled(false);
954 toDisplaySimulation();
957 //=======================================================================
958 //function : setNewMeshName
959 //purpose : update contents of LineEditNewMesh
960 //=======================================================================
962 void SMESHGUI_TranslationDlg::setNewMeshName()
964 LineEditNewMesh->setText("");
965 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
967 if ( CheckBoxMesh->isChecked() ) {
968 name = LineEditElements->text();
971 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
972 name = meshSO->GetName().c_str();
974 if ( !name.isEmpty() )
975 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
979 //=================================================================================
980 // function : GetConstructorId()
982 //=================================================================================
983 int SMESHGUI_TranslationDlg::GetConstructorId()
985 return GroupConstructors->checkedId();
988 //=================================================================================
989 // function : keyPressEvent()
991 //=================================================================================
992 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
994 QDialog::keyPressEvent( e );
995 if ( e->isAccepted() )
998 if ( e->key() == Qt::Key_F1 ) {
1004 //=================================================================================
1005 // function : setFilters()
1006 // purpose : SLOT. Called when "Filter" button pressed.
1007 //=================================================================================
1008 void SMESHGUI_TranslationDlg::setFilters()
1010 if(myMesh->_is_nil()) {
1011 SUIT_MessageBox::critical(this,
1013 tr("NO_MESH_SELECTED"));
1017 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1019 myFilterDlg->SetSelection();
1020 myFilterDlg->SetMesh( myMesh );
1021 myFilterDlg->SetSourceWg( LineEditElements );
1023 myFilterDlg->show();
1026 //=================================================================================
1027 // function : isValid
1029 //=================================================================================
1030 bool SMESHGUI_TranslationDlg::isValid()
1035 ok = SpinBox1_1->isValid( msg, true ) && ok;
1036 ok = SpinBox1_2->isValid( msg, true ) && ok;
1037 ok = SpinBox1_3->isValid( msg, true ) && ok;
1038 if (GetConstructorId() == 0) {
1039 ok = SpinBox2_1->isValid( msg, true ) && ok;
1040 ok = SpinBox2_2->isValid( msg, true ) && ok;
1041 ok = SpinBox2_3->isValid( msg, true ) && ok;
1045 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1046 if ( !msg.isEmpty() )
1048 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1054 //=================================================================================
1055 // function : onDisplaySimulation
1056 // purpose : Show/Hide preview
1057 //=================================================================================
1058 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview ) {
1059 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1061 if (isValid() && myNbOkElements) {
1062 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1064 SMESH::long_array_var anElementsId = new SMESH::long_array;
1066 anElementsId->length(aListElementsId.count());
1067 for (int i = 0; i < aListElementsId.count(); i++)
1068 anElementsId[i] = aListElementsId[i].toInt();
1070 SMESH::DirStruct aVector;
1071 if (GetConstructorId() == 0) {
1072 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1073 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1074 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1075 } else if (GetConstructorId() == 1) {
1076 aVector.PS.x = SpinBox1_1->GetValue();
1077 aVector.PS.y = SpinBox1_2->GetValue();
1078 aVector.PS.z = SpinBox1_3->GetValue();
1082 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1083 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1084 SUIT_OverrideCursor aWaitCursor;
1085 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1086 if(CheckBoxMesh->isChecked())
1087 aMeshEditor->TranslateObject(mySelectedObject, aVector, copy);
1089 aMeshEditor->Translate(anElementsId, aVector, copy);
1091 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1092 mySimulation->SetData(aMeshPreviewStruct._retn());